• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Timer Task and Server restart

 
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
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are using Netweaver Application Server
 
Wanderer
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
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).
 
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic