• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use of Timer without user interaction

 
Christian Heldstab
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all

A workmate of mine and me, we are wondering how it is possible to start a timer without user interaction.

We know that in a method of a session bean, it is possible to call createTimer on the Timer Service. This timer runs and calls the @Timeout annotated method.

In case of a batch job or anything equals, how is it possible to call createTimer? Does is is mandatory to implement a stateless session bean to start the batch or is there a possibility to do it automatically (as example, from a definition in the deployment descriptor)?

Thanks in advance.

Christian
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to create the timer by invoking the createTimer method, either in ejbCreate or in a business method of the EJB.

But I will point you to that link for ways to automatically invoke it:
http://www.onjava.com/pub/a/onjava/2004/10/13/j2ee-timers.html?page=2

Some business applications require automatically scheduling a timer task. If your business application requires the automatic creation of a timer when your application is deployed, you have the following J2EE options:

* Create the timer by invoking the EJB method: Invoke initializeTimer in the contextInitialized method of a ServletContextListener of a web module.
* Create a servlet and implement the init method to invoke the EJB method that creates the timer. Set the load-on-startup property for the servlet to automatically start the servlet when the web module is started.
* Use a Startup class using the proprietary API of your J2EE container.

I think that a nice approach would be to use EJB timers in association with Quartz.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Celinio Fernandes:
I think that a nice approach would be to use EJB timers in association with Quartz.


We have had good success with this approach. We've also used the SAR method of having things kick off on startup.
 
Christian Heldstab
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for the feedback.

Quartz seems to be a good tool, nice documented (at least the tutorials I briefly visited).


Christian
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic