Bruno,
See java.util.Timer and java.util.TimerTask. For example:
Although using Timer would do the job, I personally don't use them.
I instead prefer so do my scheduling outside of the application. In
my case I use cron and curl with a direct action. What I always had
trouble with when attempting to use timers is the problem it creates
when running multiple instances of your application.
If you use a timer inside your WO application instance, and you have
more than one instance of your application running, then you will
have more than one timer running possibly updating your file more
often than you really want.
It may be possible to configure your timer to run on only one
instance, say instance number 1. The problem here is that if
instance 1 is shutdown then no timer will be running even if their
are other instances available.
Using an outside scheduler solves these issues in a clean and
effective way.
As an extension to this method I often run the process in a separate
thread, for those actions that may take more than a few seconds to
execute.
Example:
The cron job:
0,30 6-18 * * * curl -m 60 http://example.com/cgi-bin/WebObjects/
MyApp.woa/wa/fetchNewImages
The direct action:
....
....
public WOActionResults fetchNewImagesAction() {
WOResponse aResponse = new WOResponse();
FetchNewImagesThread thread = new
FetchNewImagesThread(context());
thread.start();
aResponse.setHeader("text/plain", "content-type");
aResponse.appendContentString("Action completed successfully.");
return aResponse;
}
....
....
In this case the FetchNewImageTread is just a subclass of Thread.
Also notice that I added a constructor that takes the context() as an
argument so that my thread class has access to such things as context
().request(), context(),session(), etc.
I hope this helps. This technique has been working great for my needs.
On Feb 23, 2007, at 8:58 AM, Zak Burke wrote:
WIESEN Bruno wrote on 2/23/07 3:22 AM:
Hi all,
I have to refresh a file...so every 5 minutes an action has to be
performed! But i don't know
which method use...do you have an idea?
See java.util.Timer and java.util.TimerTask. For example:
Put this in some method called by your Application's constructor:
// 5 * 60 * 1000 == 5 minutes worth of milliseconds
// but of course you'd read that value from a props file instead
// of hard-coding a bunch of ints, right? right.
Timer t = new java.util.Timer();
t.scheduleAtFixedRate(new TimeableTask(), 0l, 5 * 60 * 1000);
public class TimeableTask extends java.util.TimerTask
{
public void run()
{
// your regularly schedule event here
}
}
zak.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/robertwalker1%
40mac.com
This email sent to [EMAIL PROTECTED]
--
Robert Walker
[EMAIL PROTECTED]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]