FWIW, I had to write a class to invoke a method on a given object at timed
intervals using the Reflection API. I use it to "automatically" refresh bean
info from my database at set intervals. I'm attaching the code, called
TimedMethodInvoker.java, and a simple example.

Works like a charm for me. Hope it helps.

--jeff

----- Original Message -----
From: "Michael Wentzel" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, August 06, 2001 5:27 AM
Subject: RE: Servllet


> > Maybe do a sleep instead of busy waiting (looping takes up
> > too much cpu
> > time).
> >
> > > > How about running an application that periodically posts to
> > > > the servlet?
> > > >
> > > >
> > > > > How can a servlet be automatically be invoked by
> > > > > itself, say peroidically?
> > > > > Usul
> > >
> > > I think a better way is to write a servlet which is configured
> > > as a load on startup servlet which forks a separate "scheduler"
> > > thread which then defines tasks to be completed at specified
> > > interval(using a properties file or init params...).  The
> > > Thread(Runnable) will essentially be a infinite loop which will
> > > check to see if it's time to run certain tasks. i.e.
> > >
> > > while(1) {
> > >     if ( /*somethings true 1*/ ) {
> > >         /*perform task 1*/
> > >     }
> > >     if ( /*somethings true 2*/ ) {
> > >         /*perform task 2*/
> > >     }
> > >     // ...
> > > }
>
> Yeah, that's the general idea.  That was the //... part any additional
> cleanup between states and a wait state.  Otherwise the process, depending
> on the performance of your separate scheduled jobs and the frequency of
> them, could pretty much lock the processor down.  This is meant as a
> rudamentary example.  This is the generic model of a scheduling
> thread/server.
>
>
> ---
> Michael Wentzel
> Software Developer
> Software As We Think - http://www.aswethink.com
>

TimedMethodInvoker.java

ExampleBean.java

Reply via email to