• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

@Timeout applies to incremental scheduler?

 
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3411
320
Android Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
reply
    Bookmark Topic Watch Topic
  • New Topic