This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 ]
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.
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.