aspose file tools
The moose likes Threads and Synchronization and the fly likes Timer and TimerTask problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Timer and TimerTask problem" Watch "Timer and TimerTask problem" New topic
Author

Timer and TimerTask problem

galven wing
Greenhorn

Joined: Mar 09, 2004
Posts: 5
hi,all:
I have a problem.I write a servlt.when the servlet does init(),
code like this:
public class T extends HttpServlet{
public void init(){
Task1 task = new Task1(); //Task1 extends TimerTask
Calendar cal=Calendar.getInstance();
Calendar newCal=newCal.set(
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH),
0,
0,
0;
Date delay = newCal.getTime();
timer.schedule(task, delay,86400000);
}
}
public class Task1 extends TimerTask{
public void run(){
// do something
}
}
when i load the servlet, task.run() will execute right now.and some times,it will not execute right now. i dont know why this will happen.
thx
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8876

It is possible that the delay Date time is already passed.


Groovy
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
I wouldn't say that the time is gone as the delay is computed right there. Maybe you cannot see the output of your task as you cannot say (the spec doesn't say) when the servlet is loaded.

./pope


blog - InfoQ.com
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Timer and TimerTask problem
 
Similar Threads
Need to compare date time in GMT
errorr in compling.. help
Call action class from timertask's run method
A question on inner class
put Vector in run(), and update him