import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.ejb.*; /** * * @author kumm */ @Singleton @Startup public class TimerTester { private static final Logger logger = Logger.getLogger(TimerTester.class.getName()); private static final String TIME_LOG_FORMAT = "yyyy.MM.dd HH:mm"; @Resource private TimerService timerService; private SimpleDateFormat simpleDateFormat = new SimpleDateFormat(TIME_LOG_FORMAT); @PostConstruct public void init() { Locale[] availableLocales = Locale.getAvailableLocales(); Locale localeDefault = Locale.getDefault(); for (int i = 0; i < availableLocales.length; i++) { Locale.setDefault(availableLocales[i]); initTimer(); } Locale.setDefault(localeDefault); } public void initTimer() { TimerConfig timerConfig = new TimerConfig("Every Sunday in "+Locale.getDefault(), false); ScheduleExpression sheduleExpression = new ScheduleExpression(). dayOfWeek(0). hour(12). minute(0); Timer timer = timerService.createCalendarTimer(sheduleExpression, timerConfig); dump(timer); } private void dump(Timer timer) { logger.log(Level.INFO, "{0} starts with {1}", new Object[]{timer.getInfo(), dateToStr(timer.getNextTimeout())}); } private String dateToStr(Date date) { return simpleDateFormat.format(date); } @Timeout public void ejbTimeout(Timer timer) { logger.log(Level.INFO, "ejbTimeout({0})", new Object[]{timer.getInfo()}); } }