aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes @Timeout applies to incremental scheduler? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "@Timeout applies to incremental scheduler?" Watch "@Timeout applies to incremental scheduler?" New topic
Author

@Timeout applies to incremental scheduler?

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 758
Use the example on p.211 from EJB in Action :

The method annotated with @Timeout to mark it as the method responsible for executing the task with the timer completes.



@Stateless
public class FlyerBean{

@Resource
private TimerService timerService;

...

public void scheduleFlyer(ScheduleExpression se, Email email){

TimeConfig tc = new TimerConfig(email, true);
Timer timer = timerService.createCalendarTime(se,tc);
...
}

@Timeout
public void send(Timer timer){
if (time.getInfo() instanceof Email){
Email email = (Email)timer.getInfo();
//Retrieve bidder/ seller and email.
}
}
}



ScheduleExpression se = new ScheduleExpression();
se.month(2).dayOfMonth(14).year(2012).hour(11).minute(30);


The code says the send method will be invoked on 2/14/2012 at 11:30.

What about a schedule expression ?


This schedule never times out. The times keeps increasing from 0:0:0, 0:20:30, 0:20:40 and so on.
The @Timeout method won't be invoked ? (I haven't tried it yet.)
@Timeout means the time when the time matches the schedule expression.
With an increasing time, will @Timeout method be invoked ?
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1678
    
  25

There is a difference between Programmatic Timers (@Timeout) and Automatic Timers (@Schedule). I have summed up the differences in chapter 9 of my notes.

A good explanation can be found in the Oracle EE6 tutorial:
Creating Programmatic Timers
To create a timer, the bean invokes one of the create methods of the TimerService interface. These methods allow single-action, interval, or calendar-based timers to be created.
. . .
When a programmatic timer expires (goes off), the container calls the method annotated @Timeout in the bean’s implementation class. The @Timeout method contains the business logic that handles the timed event.


Regards,
Frits
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 758
Hi, Frit. Thanks for your reply. In Frits notes, p.87,

This code creates a timer that expires every Monday at 12 noon.
ScheduleExpression schedule = new ScheduleExpression().dayOfWeek("Mon").hour(12);
Timer timer=timerService.createCalendarTimer(schedule);



So, if I have this

Will the timer expire ? The timer will continue to increase forever.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1678
    
  25

Himai Minh wrote:Will the timer expire ? The timer will continue to increase forever.

It will expire multiple times (and the @Timeout method will be called) based on the expression you gave.

I guess what you mean is will it ever stop? No, it won't stop unless you cancel the calendar based timer.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: @Timeout applies to incremental scheduler?