Refine search
public Collection<Timer> getAllActiveTimers() { final Collection<Timer> activeTimers = new HashSet<>(); synchronized (timerServices) { for (final TimerService timerService : timerServices) { activeTimers.addAll(timerService.getTimers()); } } return activeTimers; } }
@PostConstruct public void initialize() { ScheduleExpression scheduleExpression = new ScheduleExpression() .hour("*") .minute("*") .second("*/5"); TimerConfig timerConfig = new TimerConfig(); timerConfig.setInfo("Every 5 second timer"); timerService.createCalendarTimer(scheduleExpression, timerConfig); }
public void register(final String clientId) { sendMessage(REGISTER_ENDPOINT, applicationConfig.toJSON()); ScheduleExpression schedule = new ScheduleExpression(); schedule.second("*/10").minute("*").hour("*").start(Calendar.getInstance().getTime()); TimerConfig config = new TimerConfig(); config.setPersistent(false); Timer timer = timerService.createCalendarTimer(schedule, config); LOGGER.config(() -> timer.getSchedule().toString()); }
@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); } }
@Stateless public class JobSchedulerBean { @Resource private TimerService timerService; // @PostConstruct public void initTimer() { // set initial timer ScheduleExpression sch = new ScheduleExpression(); // set cron expression into sch timerService.createCalendarTimer(sch, new TimerConfig("myTimer", false)); } public void rescheduleTimer(int interval) { // get timer from timer service for (Timer timer : timerService.getTimers()) { if (timer != null && timer.getInfo().equals("myTimer")) { timer.cancel(); } } // schedule new timer, like in initTimer() method } @Timeout public void timeout(Timer timer) { // do the job } }
public void createCustomer(Customer04 customer) { em.persist(customer); ScheduleExpression birthDay = new ScheduleExpression().dayOfMonth(customer.getBirthDay()).month(customer.getBirthMonth()); timerService.createCalendarTimer(birthDay, new TimerConfig(customer, true)); }
synchronized public void startTimer() { ScheduleExpression schedule = new ScheduleExpression(); if (null == timezone) { log.warning("Timezone not set, using default: America/Sao_Paulo"); schedule.timezone("America/Sao_Paulo"); } else { schedule.timezone(timezone); } schedule.hour("23"); schedule.minute("00"); timerService.createCalendarTimer(schedule); }
@Singleton @Startup public class ProgrammaticTimer { @Resource TimerService timerService; public void createTimer(String timerId, int frec){ ScheduleExpression expression = new ScheduleExpression(); expression.minute("*/"+freq).hour("*"); timerService.createCalendarTimer(expression, new TimerConfig(timerId, true)); } @Timeout public void execute(){ System.out.println("----Invoked: " + System.currentTimeMillis()); } }
@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"); } }
@Override public void scheduleConfigCacheReloader() { // each time the webapp is reloaded, we don't want to create duplicate jobs Collection<Timer> timers = timerService.getTimers(); for (Timer existingTimer : timers) { LOG.debug("Found timer - attempting to cancel: " + existingTimer.toString()); try { existingTimer.cancel(); } catch (Exception e) { LOG.warn("Failed in attempting to cancel timer: " + existingTimer.toString()); } } // timer that will trigger every 60 seconds timerService.createIntervalTimer(60000L, 60000L, new TimerConfig(null, false)); }
@Stateless public class TimerSessionBean implements TimerSession { @Resource TimerService timerService; public void startTimer() { Timer timer = timerService.createTimer(200, "Created new timer"); } @Timeout public void timeout(Timer timer) { logger.info("Timeout occurred"); } }
ScheduleExpression expression = new ScheduleExpression(); expression.second(sec).minute(min).hour(hour); timerService.createCalendarTimer(expression); if (timerService.getTimers() != null) { for (Timer timer : timerService.getTimers()) if (timer.getInfo().equals(timerInfo)) timer.cancel();
@Resource TimerService timerService; @Schedule(...) @Timeout public void schedule() { ... } public void restart() { TimerConfig timerConfig = new TimerConfig(); timerConfig.setPersistent(false); timerService.createCalendarTimer(new ScheduleExpression() .second("*/10") .minute("*") .hour("*"), new TimerConfig("mySchedule", false)); }
ScheduleExpression conf = new ScheduleExpression(); conf.hour(h); conf.minute(m); conf.second(s); timerService.createCalendarTimer(conf, new TimerConfig("desc msg ", false)); LOG.log(Level.INFO, ">> Ready for: " + conf.toString());
/** * {@inheritDoc} */ public void startTimerNow(TrustPointEntity trustPoint) { TimerConfig timerConfig = new TimerConfig(); timerConfig.setInfo(trustPoint.getName()); timerConfig.setPersistent(false); Timer timer = this.timerService.createSingleActionTimer(1000 * 10, timerConfig); LOG.debug("created single action timer for trustpoint " + trustPoint.getName() + " at " + timer.getNextTimeout().toString()); }
@Stateless // or @Singleton public class MyTimerEJB { @Resource private TimerService timerService; @Timeout public void existingTimeoutMethod() { ... } public void fireTimeoutAsynchronouslyAlmostImmediately() { timerService.createSingleActionTimer(10, new TimerConfig(null, false)); } }
@PostConstruct public void startScheduler() { TimerService timerService = sessionContext.getTimerService(); logger.info("Current running timers: {}", timerService.getTimers().toString()); for (Timer t : timerService.getTimers()) { t.cancel(); logger.info("killed the timer service: {}", t); } TimerConfig timerConfig = new TimerConfig(); timerConfig.setPersistent(false); Timer createdIntervalTimer = sessionContext.getTimerService().createIntervalTimer(0, 5000, timerConfig); logger.info("Created new Timer: {}", createdIntervalTimer); }
/** * Schedule a job for regular execution. * <p/> * @param job * @param when The ScheduleExpression dictating when the job should be run. */ public void scheduleJobOnCalendar(Jobs job, ScheduleExpression when) { TimerConfig config = new TimerConfig(); config.setInfo(job.getId()); timerService.createCalendarTimer(when, config); }
@PostConstruct public void init() { ts.createIntervalTimer(0l, TimeUnit.SECONDS.toMillis(1), new TimerConfig("a test timer", false)); }
public Timer createCalendarTimer(ScheduleExpression schedule) throws IllegalArgumentException, IllegalStateException, EJBException { assertAllowedIn("TimerService.createCalendarTimer"); return timerService.createCalendarTimer(schedule); }