aspose file tools*
The moose likes Servlets and the fly likes TimerTask and Actions (Servlets) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "TimerTask and Actions (Servlets)" Watch "TimerTask and Actions (Servlets)" New topic
Author

TimerTask and Actions (Servlets)

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
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 ]

By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Can you explain what you mean by "context listener".
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
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 ]
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
try this link

http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets4.html


java j2ee job interview questions with answers | Learn the core concepts and the key areas
Manesh Kumar
Ranch Hand

Joined: Mar 21, 2006
Posts: 94
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 ]

Manesh
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
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
Bartender

Joined: Oct 14, 2005
Posts: 18141
    
    8

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
 
subject: TimerTask and Actions (Servlets)
 
Similar Threads
WebSphere 5.1 and JTA
Timer Task
TimerTask Execution
Progress Bar
Call action class from timertask's run method