You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Hohlen, John" <JH...@erac.com> on 2001/12/27 17:24:39 UTC

Resetting Application Scope Data Once A Day

> Hi.
> 
>      I was wondering if any other Struts developers have a situation
> similar to ours regarding the resetting "Application" scoped data once a
> day?  If so, I'd like to know what solution you used.
> 
>      Here's our particular situation:
>      
>      We have choices on an input screen, a drop-down menu to be exact,
> that come from a database.  The choices only change once a day -- in the
> middle of the night after a batch job runs on another machine.   Since
> these choices are always the same, we don't want to take a database hit
> every time a user comes to our particular page.  Therefore, we've elected
> to store the choices in hashmap scoped at the Application level.  
>      However, once a day we would like to update the hashmap.  Ideally, at
> a particular time after we know the batch job on the other machine has.
> For example, 4:00 a.m.   We would like this time to be configurable via
> the web.xml file.  We've extended both the Struts "ActionServlet" and
> "Action" classes to do some additional processing that we need.  Hence,
> all our action classes derive from our extended Struts "Action" class.  We
> use our extended Struts "ActionServlet" class as our main servlet.
> 
>      My question is this:  
> 
>      If we write some logic to monitor for the first request that occurs
> after each day rollover time (e.g. 4:00 a.m.), should this logic reside in
> the Servlet or our base Action class?  Either way, this day rollover check
> would have to occur every time a HTTP request is made.    Is this a
> reasonable solution?  Or would a better solution be to spawn a separate
> thread that simply sleeps until the configured time each day (e.g 4:00
> a.m.) and then wakes up to update the Application scoped hashmap? 
>      Has anyone addressed this need before?
> 
> Thanks,
> 
> John
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Resetting Application Scope Data Once A Day

Posted by Ted Husted <hu...@apache.org>.
You might consider setting up an administrative action that would
refresh the application attributes on demand. The URL for the admin
action could be called as part of the batch job, possibly using Cactus
or some other utility designed to submit a HTTP request. 

So you would simply have something like

http://mydomain.tld/myapp/Admin/refreshMenu.do?password=glock3nspi3l

That you could call yourself, or some external process could call on a
schedule, with all the other batch jobs.

I don't know if this applies, but you should also consider any
latency/threading issues that may occur if the application data changes
in the middle of a transaction. Would anything bad happen if someone
used the 3:59a menu at 4:01a ?

If so, you may need to keep two sets of the data, and flip back and
forth (3:59a was batch 0, 4:01a is batch 1, tomorrow would be batch 0
again), and include the batch id as part of the request. Of course, this
assumes that no one will their session active for 24+ continous hours
and be able to submit Wednesday's page on Friday.


"Hohlen, John" wrote:
> 
> > Hi.
> >
> >      I was wondering if any other Struts developers have a situation
> > similar to ours regarding the resetting "Application" scoped data once a
> > day?  If so, I'd like to know what solution you used.
> >
> >      Here's our particular situation:
> >
> >      We have choices on an input screen, a drop-down menu to be exact,
> > that come from a database.  The choices only change once a day -- in the
> > middle of the night after a batch job runs on another machine.   Since
> > these choices are always the same, we don't want to take a database hit
> > every time a user comes to our particular page.  Therefore, we've elected
> > to store the choices in hashmap scoped at the Application level.
> >      However, once a day we would like to update the hashmap.  Ideally, at
> > a particular time after we know the batch job on the other machine has.
> > For example, 4:00 a.m.   We would like this time to be configurable via
> > the web.xml file.  We've extended both the Struts "ActionServlet" and
> > "Action" classes to do some additional processing that we need.  Hence,
> > all our action classes derive from our extended Struts "Action" class.  We
> > use our extended Struts "ActionServlet" class as our main servlet.
> >
> >      My question is this:
> >
> >      If we write some logic to monitor for the first request that occurs
> > after each day rollover time (e.g. 4:00 a.m.), should this logic reside in
> > the Servlet or our base Action class?  Either way, this day rollover check
> > would have to occur every time a HTTP request is made.    Is this a
> > reasonable solution?  Or would a better solution be to spawn a separate
> > thread that simply sleeps until the configured time each day (e.g 4:00
> > a.m.) and then wakes up to update the Application scoped hashmap?
> >      Has anyone addressed this need before?
> >
> > Thanks,
> >
> > John
> >
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>