views:

94

answers:

1

I would like to run a background task on some interval from a web application I have deployed on Websphere 6.1 clustered environment. The task will access a database, send emails, and write to the database.

I was thinking about kicking off a thread when the web app is first loaded, as suggested here: http://stackoverflow.com/questions/791986/background-thread-for-a-tomcat-servlet-app.

Since it is a clustered environment, what would be the best way to NOT have task run on each individual node of the cluster?

+1  A: 

Have a look at the WAS Scheduler service.

It says of clustered environments:

Scheduler daemons in a cluster

When multiple schedulers are configured to use the same tables (as is the case in a clustered environment), any of the daemons can find a task and set the alarm in its Java virtual machine (JVM). The task is executed in the virtual machine where the scheduler daemon first runs, until the daemon is stopped and another daemon starts. If an application on server1 schedules a task to run and server2 was started before server1, then the task runs on server2.

McDowell