• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Timer Task

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens if a TimerTask object is deployed in a clustered environment? Does it schedule a new task on each node?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic