• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TimerTask and Actions (Servlets)

 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you explain what you mean by "context listener".
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 288
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic