File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TimerTask and Actions (Servlets)

 
Dale DeMott
Ranch Hand
Posts: 515
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get a TimerTask setup so I can have a regularly occurring task fire every X days. Problem is I can't get the task to fire at all. The action fires.. thats great.. but when the time comes for the TimerTask to fire, nothing happens. I have started the TimerTask via a url Action call (inside the execute) and I have also started the task via the init in the Action. Neither seem to fire. Has anyone done this before and what might I change in order to get this to work.

TIA!
[ March 22, 2006: Message edited by: Dale DeMott ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without seeing your code, it would be hard for anyone to help you.

Side note:
If you're using a Servelet 2.3 or higher container, you might want to take the timer code out of the servlet/action and put it in a plain old java object; which you can instanciate and initialize with a context listener.
 
Dale DeMott
Ranch Hand
Posts: 515
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain what you mean by "context listener".
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dale DeMott:
Can you explain what you mean by "context listener".


http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContextListener.html
 
Dale DeMott
Ranch Hand
Posts: 515
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. Here is the source for both the NOW Servlet and the TimerTask code.

This is the servlet code



This is the TimerTask that is to execute.


[ March 22, 2006: Message edited by: Dale DeMott ]
 
Manesh Kumar
Ranch Hand
Posts: 94
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure, but you can try to place the time (Timer object) declared at class level variable, so that it will not be collection by GC after method is executed.
Or you can set the timer object at application scope.


Correct me if I am wrong.

[ March 23, 2006: Message edited by: Dilip Kumar Jain ]
[ March 23, 2006: Message edited by: Dilip Kumar Jain ]
 
Dale DeMott
Ranch Hand
Posts: 515
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems the problem I'm having is with this line




When I use the following method signature...

time.schedule(insertMonthlyRecordsTimedTask, java.util.Date x, long y);
where x represents the date the task is fired off.
where y represents number of milliseconds until the task is fired off again [repeated].

this DOES NOT work...

BUT when I use
time.schedule(insertMonthlyRecordsTimedTask, long a, long b);
where a represents number of milliseconds to wait until the first time the event is fired off.
where b represents number of milliseconds until repeated.

this DOES work

Very odd. Any ideas??
[ March 24, 2006: Message edited by: Dale DeMott ]
 
Paul Clapham
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obviously the Timer itself is working. So that suggests that your inputs aren't what you think they are. For example if you provided "March 24, 2106, 11:30:00" as your starting date then you wouldn't see anything happening for quite a while.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic