How can I configure a schedule intervals:
@Schedule(persistent=true, minute="*", second="*/5", hour="*")
outside of the application code?
The EJB timer service provides a reliable and transactional notification service for timed events. Timer notifications may be scheduled to occur at a specific time, after a specific elapsed duration, or at specific recurring intervals. You can define callback methods on your EJB to receive these time-based events.
Nonpersistent programmatic timers are created by calling TimerConfig. setPersistent(false) and passing the TimerConfig object to one of the timer-creation methods.
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");     }  } According to the EJB 3.1 specification, automatic timers can be configured through annotations or through the ejb-jar.xml deployment descriptor.
18.2.2 Automatic Timer Creation
The Timer Service supports the automatic creation of a timer based on metadata in the bean class or deployment descriptor. This allows the bean developer to schedule a timer without relying on a bean invocation to programmatically invoke one of the Timer Service timer creation methods. Automatically created timers are created by the container as a result of application deployment.
And my understanding of the deployment descriptor XLM schema is that you define it using a <timer> element inside a <session> element.
<xsd:element name="timer"              type="javaee:timerType"              minOccurs="0"              maxOccurs="unbounded"/> See the definition of the timerType complex type for the details (in particular the schedule and timeout-method elements).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With