Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>@Schedule</strong></p> <p>If you are using Ejb 3.1 (glassfish 3.x), you may use the @Schedule annotation to have the container invoke a method in a specified interval or at a given calendar time. Allowing you to avoid handling threads in your own code</p> <p><a href="http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html" rel="nofollow">Read about ejb 3.1 timer</a></p> <pre><code>@Stateless public class LabbBean { @EJB WorkerEjb workerEjb; @Schedule(second="*/5", minute="*",hour="*", persistent=false) public void myMethod() { for (all jobs found in db){ workerEjb.workerMethod(job); } } } @Stateless public class WorkerEjb { @Asynchronous public void workerMethod(job) { //Send emails } } </code></pre> <p>If you wanted to do the work in separate threads, the @Schedule annotated method could call a worker-ejb with the worker-method annotated as @Asynchronous</p> <p><strong>@Timeout</strong></p> <p>I just realised you wanted the schedule to be initiated from the database. An option the would be to initiate a bunch of timers programmatically using a @Singleton ejb with @Startup annotation. The timeout annotated method would be called in separate threads if some timers run out at the same time.</p> <pre><code>@Singleton @Startup public class LabbBean { @Resource protected TimerService timerService; @PostConstruct public void init() { //Init your timers from the data in the database here for (all your timers) { TimerConfig config = new TimerConfig(); config.setInfo("timer1"); config.setPersistent(false); ScheduleExpression schedule = new ScheduleExpression(); schedule.dayOfMonth(10); schedule.minute(2); timerService.createCalendarTimer(schedule, config); } } //method called when timeout occurs @Timeout public void timeoutHandler(Timer timer) { String name = timer.getInfo().toString(); System.out.println("Timer name=" + name); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload