How can I configure a schedule intervals:
@Schedule(persistent=true, minute="*", second="*/5", hour="*")
outside of the application code?
Here is an example of a scheduling in the deployment descriptor:
<session>
<ejb-name>MessageService</ejb-name>
<local-bean/>
<ejb-class>ejb.MessageService</ejb-class>
<session-type>Stateless</session-type>
<timer>
<schedule>
<second>0/18</second>
<minute>*</minute>
<hour>*</hour>
</schedule>
<timeout-method>
<method-name>showMessage</method-name>
</timeout-method>
</timer>
</session>
Another way of configuring timers is with a programmatic scheduling.
@Singleton
@Startup
public class TimedBean{
@Resource
private TimerService service;
@PostConstruct
public void init(){
ScheduleExpression exp=new ScheduleExpression();
exp.hour("*")
.minute("*")
.second("*/10");
service.createCalendarTimer(exp);
}
@Timeout
public void timeOut(){
System.out.println(new Date());
System.out.println("time out");
}
}