You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <ma...@reumann.net> on 2002/06/07 15:46:50 UTC
populating Collections one time?
I know this isn't a struts specific question and is probably more
appropriate for a servlets list but possibly struts has a way of
handling things that I'm unaware of. (Struts people seem to be the
creme of the crop also so I value your suggestions:)
I'm sure this topic has come up before but I'm having difficulty
getting the correct keywords in the archives to come up with the
answers I know are out there. Actually this is a very simple question
but want to know how you guys handle it...
You have a bunch of Collections of different beans that do not change
frequently (if they do a restart of the server is fine ). For example
maybe a Collection of State beans or Collection of JobTitle objects.
These Collections need to be populated from a database call but after
that I want them around for any user to use without having to make
another hit to the database to populate the collection.
First, I know the way I'm doing it now is not the proper way but I
have a question about it for curiosity's sake. Currently I have a
class that has private static fields like List stores (which is an
ArrayList of Store beans ). When a call is made to getStores() it
checks if stores is null, and only if it's null does it make the hit
to the db to populate. Question:
>From what I can tell this List then won't have to get repopulated
again for as long as this user session's remains active. It appears
that the List will even remain populated when that user's session
expires and the server remains up. I'm not positive about this later
part though and was curious if that was the case? What if no sessions
are active... will the List still remain populated or does it get
garbage collected when no sessions are present?
Now would a better way than above be to have a servlet load on start
up and in the init method make calls to populate these Collections?
Should they then be put in the ServletContext? or should I just keep
them like above knowing that any call to getStores() from a class
would not result in another hit to the db and only the first user
takes the performance hit? I'm not sure how this later behavior is
affected when no sessions are present and when new sessions start up.
I want the collections to remain as long as the server is up.
Thanks for any input on the best ways to handle this. If there are
some links covering this I'd appreciate it, thanks again.
--
Rick
mailto:maillist@reumann.net
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: [struts-atlanta] populating Collections one time?
Posted by Robert Taylor <rt...@mulework.com>.
Rick,
As for where to put them, I would place them in the ServletContext scope.
As for how to manage them, you might consider having some sort of cache
manager
which periodically refreshes the cache.
As for population, you could either use a lazy loading strategy or just
initialize
all static data when the web app cranks up (ContextListener or Struts
Plugin).
HTH,
robert
> -----Original Message-----
> From: Rick Reumann [mailto:maillist@reumann.net]
> Sent: Friday, June 07, 2002 9:47 AM
> To: Struts List
> Cc: Atlanta Struts
> Subject: [struts-atlanta] populating Collections one time?
>
>
> I know this isn't a struts specific question and is probably more
> appropriate for a servlets list but possibly struts has a way of
> handling things that I'm unaware of. (Struts people seem to be the
> creme of the crop also so I value your suggestions:)
>
> I'm sure this topic has come up before but I'm having difficulty
> getting the correct keywords in the archives to come up with the
> answers I know are out there. Actually this is a very simple question
> but want to know how you guys handle it...
>
> You have a bunch of Collections of different beans that do not change
> frequently (if they do a restart of the server is fine ). For example
> maybe a Collection of State beans or Collection of JobTitle objects.
> These Collections need to be populated from a database call but after
> that I want them around for any user to use without having to make
> another hit to the database to populate the collection.
>
> First, I know the way I'm doing it now is not the proper way but I
> have a question about it for curiosity's sake. Currently I have a
> class that has private static fields like List stores (which is an
> ArrayList of Store beans ). When a call is made to getStores() it
> checks if stores is null, and only if it's null does it make the hit
> to the db to populate. Question:
>
> >From what I can tell this List then won't have to get repopulated
> again for as long as this user session's remains active. It appears
> that the List will even remain populated when that user's session
> expires and the server remains up. I'm not positive about this later
> part though and was curious if that was the case? What if no sessions
> are active... will the List still remain populated or does it get
> garbage collected when no sessions are present?
>
> Now would a better way than above be to have a servlet load on start
> up and in the init method make calls to populate these Collections?
> Should they then be put in the ServletContext? or should I just keep
> them like above knowing that any call to getStores() from a class
> would not result in another hit to the db and only the first user
> takes the performance hit? I'm not sure how this later behavior is
> affected when no sessions are present and when new sessions start up.
> I want the collections to remain as long as the server is up.
>
> Thanks for any input on the best ways to handle this. If there are
> some links covering this I'd appreciate it, thanks again.
>
>
> --
>
> Rick
> mailto:maillist@reumann.net
>
>
> ------------------------ Yahoo! Groups Sponsor ---------------------~-->
> Tied to your PC? Cut Loose and
> Stay connected with Yahoo! Mobile
> http://us.click.yahoo.com/QBCcSD/o1CEAA/Zr0HAA/nhFolB/TM
> ---------------------------------------------------------------------~->
>
> To unsubscribe from this group, send an email to:
> struts-atlanta-unsubscribe@yahoogroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>