Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Timer Task and Server restart  RSS feed

 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a background scheduler that runs a timerTask periodically to run a job. Sometimes We restart the server and thus lose the status of the job as it always shows up as running even after server restart

Is there any way we can know that this job hasn't been attended due to server restart and change the status of job to interrupted

In other words how can I catch the server restart.
We are using clustered instances

Thanks a lot in advance
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which server are you using? Most of the servers provide a functionality to hook on some startup/shutdown classes associated with the startup/shutdown of the server. For instance this link details the same for weblogic.
You can inform your scheduler process during the execution of these classes.
[ January 09, 2008: Message edited by: Nitesh Kant ]
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately server we are using doen't provide any notification mechanism
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are using Netweaver Application Server
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know anything about Netweaver. But couldn't you write the status in a file, or a database entry? Write one thing when you start the job, and something else when you stop it. Then whenever the application starts up, it can check this file and look at the last entry to determine the latest status, and whether/when the job should be rescheduled.
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jim I am using same mechanism with only diff that I am associating a server node name also with My scheduler
Now my only question is that will it be safe for my scheduler (which extends timer task) to have non-static private variables

I will be initializing scheduler through constructor and this variable will also be initialsed there itself.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Gaurav]: Now my only question is that will it be safe for my scheduler (which extends timer task) to have non-static private variables

Yes, if you're careful. The task will run in a different thread than it was initialized in, so you need to pay attention to whether the variables are used in two different threads, or just one. Since you're setting them in the constructor, which is necessarily before the task is run, they must be used in two threads. Therefore you need to either use some protection (synchronization/locking/volatile) when accessing them, or simply make the variables final (which is easier whenever it's possible at all).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!