4

I'd like to create a programmable scheduler which triggers once per day. It has to trigger exactly at the same hour everyday whether Daylight Savingtime is on or off. So if it was set for 6 o'clock in "Europe/Berlin" (UTC+1) while DST is off, it should also trigger at 6 o'clock when DST is on (UTC+2).

I would like to use EJB TimerService but could not find anything regarding DST awareness.

Some examplary code:


import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.ScheduleExpression;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.TimerService;


@Singleton
@Startup
public class MyScheduler
{
    @Resource
    private TimerService timerService;

    @Timeout
    void myCallbackMethod ()
    {
        //do something ...
    }

    @PostConstruct
    void init()
    {
        ScheduleExpression scheduleExpression = new ScheduleExpression();

        scheduleExpression.hour("6");
        scheduleExpression.timezone("Europe/Berlin");

        timerService.createCalendarTimer(scheduleExpression);
    }
}

I used the ScheduleExpression because i figuered setting the timezone for the timer was done there. Please correct me if i'm wrong.

Would the above code do as i explained/wanted?

I found another way to do it in this answer https://stackoverflow.com/a/20388073/2940429, but i would appreciate a more comfortable way like the one above.

timbernasley
  • 490
  • 9
  • 21

0 Answers0