Deploy following code in Wildfly 8.2.0 or 8.1.0.Final
@Singleton
@Startup
public class IntervalDemo {
@Resource
private TimerService timerService;
@PostConstruct
private void init()
{
TimerConfig config = new TimerConfig();
config.setPersistent(false);
System.out.println("...initializing timer...");
ScheduleExpression exp = new ScheduleExpression();
exp.hour("*").minute("*");
exp.second("*/5");
timerService.createCalendarTimer(exp,config);
}
@Timeout
public void process(Timer timer)
{
System.out.println(">> Current Time " + new Date());
}
}
Observed output:
18:18:34,792 INFO [stdout] (EJB default - 3) >> Current Time Fri Feb 26 18:18:34 IST 2016
18:18:34,938 INFO [stdout] (EJB default - 4) >> Current Time Fri Feb 26 18:18:34 IST 2016
18:18:35,001 INFO [stdout] (EJB default - 8) >> Current Time Fri Feb 26 18:18:35 IST 2016
18:18:35,036 INFO [stdout] (EJB default - 1) >> Current Time Fri Feb 26 18:18:35 IST 2016
18:18:35,116 INFO [stdout] (EJB default - 5) >> Current Time Fri Feb 26 18:18:35 IST 2016
18:18:35,255 INFO [stdout] (EJB default - 9) >> Current Time Fri Feb 26 18:18:35 IST 2016
18:18:35,288 INFO [stdout] (EJB default - 7) >> Current Time Fri Feb 26 18:18:35 IST 2016