Er, here it is again... hoping I am less than 30K moderator limit this time! ----------------------- Create a class, say "CheckRemoteTask" that extends java.util.TimerTask and put your webservice checking code in the run() method. If you are interaction with EOF, then create an editing context in your CheckRemoteTask and use a try/finally to make sure you unlock when finished with it like this....
myEditingContext(); try { // Check webservice for new data // do stuff here, create new EO's using the new data
myEditingContext().saveChanges();
} finally { myEditingContext().unlock(); }
Then to schedule the task to run every 30 seconds just override didFinishLaunching in Application to scheduled the CheckRemoteTask, like this ...
protected Timer myTimer; /** * Method invoked when the application has finished launching. */ public void didFinishLaunching() { super.didFinishLaunching();
myTimer = new Timer(true); // run it every 30 seconds starting first task 1 second from now myTimer.schedule(new CheckRemoteTask(), 1000l, 30*1000l);
}
If you have multiple instances of your app running, then you need to create a separate "singleton" app that fires a direct action to your multiple instance app every 30 secs and the DA can run the code. This ensures the code runs only once every 30 secs in whichever of the multiple instances the adaptor passes the DA to ..... but don't worry about that if you have only one instance of your app running.
HTH,
-Kieran ________________________________________________________________
On Apr 24, 2006, at 10:56 AM, Philippe Lafoucrière wrote: Is there a way to create a continous loop in wo ? I have to check a distant webservice every 30 seconds and fetch new data if available.
|