• 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

Use of Timer without user interaction

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 563
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic