File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Timer Task Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Timer Task" Watch "Timer Task" New topic
Author

Timer Task

visu Nekk
Ranch Hand

Joined: Sep 06, 2005
Posts: 122
What happens if a TimerTask object is deployed in a clustered environment? Does it schedule a new task on each node?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

There is nothing in TimerTasks to make them cluster aware, so it schedules a new task for each JVM. You could implement this yourself, by having them check whether another is already running (via some locking mechanism such as a process available over RMI). Or if your clustered environment is an ejb container you could use an EJB Timer service.
[ May 21, 2008: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

It depends on where you create the TimerTask, if that component is being started at every node, the timer task also will be run.
TimerTask by itself would not have the idea about the clustered environment, unless you put the intelligence in it.


apigee, a better way to API!
visu Nekk
Ranch Hand

Joined: Sep 06, 2005
Posts: 122
Thanks Nitesh and Paul, Is RMI the only way to add intelligence or is there any other way? I am running my TimerTask in JBoss server. Please guide me in brief on adding intelligence to it.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If your timer runs in a clustered environment, you need some network technology that can be accessed from each node in the cluster. RMI was just an off-hand suggestion. You could equally use a database, or a shared JNDI namespace. The logic is pretty simple: before starting your timer check whether there is already already running. Have each timer update something via whichever repository you choose to alert to others that they are running.

However, if you are using JBoss and EJB 3, why not use an EJB Timer Service? It can do all the above for you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Timer Task
 
Similar Threads
The <jar> type doesn't support the nested "copy" element.
WA #1.....word association
ant Junit vs UI Junit
Windows XP/NT help -- vmstat functionality
Problem: failed to create task or type for Cause: The name is undefined.