Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

run a code in background

 
Pravin Shirke
Ranch Hand
Posts: 152
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
I want to run a code in background just like daemon thread or something like that which will check the current date and eventually fire a database related query once the date matches. Now my question is how should i do this. whether to use listener or something else. i am not sure where to start from. I am stuck up here Any help would be appreciated.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Service Wrapper may be for you: http://wrapper.tanukisoftware.org/doc/english/introduction.html
 
Pravin Shirke
Ranch Hand
Posts: 152
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Ulff,
But i want to implement it in a web application. like if the date has matched with my code then i want to fire a query or something sort of it.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to implement it in a web application.
I see. You should have mentioned that, or posted the question in the Servlets forum to make that clear.

If you already have a web app running you can start background jobs at specific times (or specific intervals) using the java.util.Timer and TimerTask classes.
 
Pravin Shirke
Ranch Hand
Posts: 152
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii ulff,
thanks for the reply. what i want is that in my web application. for e.g: i have a page CreateExam where exams are scheduled. Once the exam has been conducted on the specified date i want to delete that record automatically after the exam date. now for implementing this what should i use a Listener may be i guess or something else which you guys can suggest me the best.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at the classes I mentioned? You can set those up in a servlet context listener when the web app is started.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you can use the session's timeout mechanism for this instead. For each request, set the maximum inactive time to be just after the exam date (you can use a Filter for this). Then have a HttpSessionListener remove the record in its sessionDestroyed method.
 
Pravin Shirke
Ranch Hand
Posts: 152
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you guys, i have decided to go with servlet context listener as i need to do many things throughout my application automatically based on an event like date or time. i will try and tell you what happened. thanks for the help and support. thank you very everybody
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic