Refine search
@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); }
AutoTimer autoTimer = new AutoTimer(); autoTimer.getTimerConfig().setInfo(timer.getInfo()); autoTimer.getTimerConfig().setPersistent(timer.isPersistent()); scheduleExpression.dayOfMonth(schedule.getDayOfMonth()); scheduleExpression.dayOfWeek(schedule.getDayOfWeek()); scheduleExpression.hour(schedule.getHour()); scheduleExpression.minute(schedule.getMinute()); scheduleExpression.month(schedule.getMonth());
public TimerImpl loadAutoTimer(ScheduleExpression schedule, TimerConfig timerConfig, Method timeoutMethod) { return this.createCalendarTimer(schedule, timerConfig.getInfo(), timerConfig.isPersistent(), timeoutMethod); }
for (ScheduleInfo scheduleInfo : info.schedules) { ScheduleExpression expr = new ScheduleExpression(); expr.second(scheduleInfo.second); expr.minute(scheduleInfo.minute); expr.hour(scheduleInfo.hour); expr.dayOfWeek(scheduleInfo.dayOfWeek); expr.year(scheduleInfo.year); TimerConfig config = new TimerConfig(); config.setInfo(scheduleInfo.info); config.setPersistent(scheduleInfo.persistent);
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()); }
public void createTimer(String days, String hours, String minures) { removeTimer(); ScheduleExpression scheduleExpression = new ScheduleExpression(); if (days != null) { scheduleExpression.dayOfMonth(datys); scheduleExpression.hour(hours); scheduleExpression.minute(minutes); TimerConfig timerConfig = new TimerConfig(); timerConfig.setInfo(TIMER_NAME); Timer timer = timerService.createCalendarTimer(scheduleExpression, timerConfig); for (Timer timer : timerService.getTimers()) { if (TIMER_NAME.equals(timer.getInfo())) { timer.cancel();
@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); } }
try { timer = timerService.createCalendarTimer( new ScheduleExpression().month(month).dayOfMonth(day).hour(hour).minute(min), new TimerConfig(Constante.IMPORT_TIMER_NAME, false)); LOGGER.info("Last geoloc import: {}", timer.getNextTimeout()); } catch (IllegalArgumentException ex) {
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)); }
@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 } }
/** * {@inheritDoc} */ public void startTimer(String cronSchedule) throws InvalidCronExpressionException { LOG.debug("start document service's cleanup task timer"); if (null == cronSchedule || cronSchedule.isEmpty()) { // TODO: error message sufficient? or explode here?... LOG.error("No interval set for document service cleanup task!"); return; } // remove old timers cancelTimers(); TimerConfig timerConfig = new TimerConfig(); timerConfig.setInfo(TIMER_ID); timerConfig.setPersistent(true); ScheduleExpression schedule = getScheduleExpression(cronSchedule); Timer timer; try { timer = this.timerService .createCalendarTimer(schedule, timerConfig); } catch (Exception e) { LOG.error("Exception while creating timer for document service " + "cleanup task: " + e.getMessage(), e); throw new InvalidCronExpressionException(e); } LOG.debug("created timer for document service cleanup task: next=" + timer.getNextTimeout().toString()); }
@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)); }
@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()); } }
@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)); }
private Timer createTimerInternal(long initialDuration, long intervalDuration, Serializable info) throws IllegalArgumentException, IllegalStateException, EJBException { TimerConfig tc = new TimerConfig(); tc.setInfo(info); return createTimerInternal(initialDuration, intervalDuration, tc); }
TimerConfig tc = new TimerConfig(); String info = sch.getInfo(); if (info != null && !info.equals("")) { tc.setInfo(info); tc.setPersistent(persistent); TimerPrimaryKey tpk = createTimer(containerId, applicationId, ts, tc, server_name); if( logger.isLoggable(Level.FINE) ) {
import javax.annotation.Resource; import javax.ejb.Stateless; import javax.ejb.Timeout; import javax.ejb.Timer; import javax.ejb.TimerConfig; import javax.ejb.TimerService; @Stateless public class TimerBean { @Resource protected TimerService timerService; @Timeout public void timeoutHandler(Timer timer) { String name = timer.getInfo().toString(); System.out.println("Timer name=" + name); } public void startTimer(long initialExpiration, long interval, String name){ TimerConfig config = new TimerConfig(); config.setInfo(name); config.setPersistent(false); timerService.createIntervalTimer(initialExpiration, interval, config); } }
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());
@PostConstruct public void init() { ts.createIntervalTimer(0l, TimeUnit.SECONDS.toMillis(1), new TimerConfig("a test timer", false)); }
/** * {@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()); }