What is the timer service in Java?

09 Apr.,2024

 


  • public interface 

    TimerService

    The TimerService interface provides enterprise bean components with access to the container-provided Timer Service. The EJB Timer Service allows stateless session beans, singleton session beans, message-driven beans, and EJB 2.x entity beans to be registered for timer callback events at a specified time, after a specified elapsed time, after a specified interval, or according to a calendar-based schedule.

    Since:

    EJB 2.1
  • In EJB 3.0 TimerService.createTimer(initialDuration, intervalDuration, TimerID) method is accepting only initialDuration and intervalDuration arguments.

    The problem is I want to run timer on 1st of every month and I can not set my timer using cron expression like in EJB 3.1 TimerService.
    Some workaround is like run on daily base and check the date inside @Timeout method if its '1st of month' but that is not appropriate way.

    I went through many example/tutorials online but no luck. Is there any other way to implement this scenario?

    What is the timer service in Java?

    EJB 3.0 TimerService - Run timer on 1st day of every month