my dog learned polymorphism*
The moose likes Servlets and the fly likes run a code in background Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "run a code in background" Watch "run a code in background" New topic
Author

run a code in background

Pravin Shirke
Ranch Hand

Joined: Apr 05, 2008
Posts: 150

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.


[Vipassana] - It is seeing the reality as it is, And not as you want it to be.!!!
SCJP1.5.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41184
    
  45
The Java Service Wrapper may be for you: http://wrapper.tanukisoftware.org/doc/english/introduction.html


Ping & DNS - my free Android networking tools app
Pravin Shirke
Ranch Hand

Joined: Apr 05, 2008
Posts: 150

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
Marshal

Joined: Mar 22, 2005
Posts: 41184
    
  45
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

Joined: Apr 05, 2008
Posts: 150

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
Marshal

Joined: Mar 22, 2005
Posts: 41184
    
  45
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

Joined: Oct 27, 2005
Posts: 19656
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Pravin Shirke
Ranch Hand

Joined: Apr 05, 2008
Posts: 150

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: run a code in background
 
Similar Threads
J2EE and Multithreading
Running background Services on a schedule
Clear validation message dynamically for the Datepicker
code that runs automatically to update sql tables on a specified date and time
get time information from oracle DATE field