How can I automatically invoke a servlet periodically at specified time intervals, like cron?

Alex Chaffee

You can do this using Java Threads.

1. Schedule a servlet to load on server startup. See How can I set a servlet to load on startup of the container, rather than on the first request?

2. In this servlet's init() method, spawn a thread.

3. In this thread's run() method, calculate the number of milliseconds to wait until the task should be performed. Then call Thread.sleep(msec). Then do the task, and loop (infinitely).

The java.util.Timer class can help a lot. See

See also How can I automatically invoke a servlet at regular time intervals using Resin?
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact