| 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
|
 |
 |
|
|
subject: Timer and TimerTask problem
|
|
|