views:

198

answers:

5

I'd like advice regarding scheduling execution within a Java web application. (currently running on Tomcat, but I'd like to avoid anything tomcat-specific).

I think the following defines the aspect of my problem I'm interested in.

Consider an application that polls a set of files for updates periodically. I'd like to provide a user interface that allows a user to define the polling interval for a given file independently, and have the execution schedule update according to user input.

How can I achieve this safely in a web app?

+2  A: 

Look at Quartz.

Adeel Ansari
A: 

Using only web layer (aka Tomcat) it is impossible. Review third-party scheduler (for example Quartz).

Dewfy
A: 

There is no standard way to do this in a J2EE application and you are not supposed to use threading in your apps. You can either use vendor-specific features (JBoss has a timer service) or use a third-party service.

Maurice Perry
A: 

You can use Quartz or Spring Batch

Firstthumb
+2  A: 

Create a plain-old Java polling process which polls the files. It connects to your webapp's database to get the polling interval, and whatever other settings that can be user defined by the interface.

Then create a simple web interface which reads and writes to the same table/database (polling intervals and whatever). Done!

karim79