Java Reference
In-Depth Information
The PollerBean will be injected into our scheduler so that we can turn off polling,
once there are no more tickets to sell:
@Stateless
public class AutomaticSellerBean
{
@Inject TheatreBox theatreBox;
@Inject PollerBean pollerBean;
private final static Logger logger =
Logger.getLogger(AutomaticSellerBean.class.getName());
@Resource
private TimerService timerService;
public void cancelTimers() {
for (Timer timer :
timerService.getTimers()) {
timer.cancel();
}
}
@Schedule(dayOfWeek = "*", hour = "*",
minute = "*", second = "*/30",year="*",
persistent = false)
public void backgroundProcessing()
{
int seatId = findSeat();
if (seatId == -1) {
pollerBean.setPollingActive(false);
cancelTimers();
logger.info("Scheduler gone!");
return ; // No more seats
}
theatreBox.buyTicket(seatId);
Search WWH ::




Custom Search