本文整理汇总了Java中javax.ejb.TimerService.createTimer方法的典型用法代码示例。如果您正苦于以下问题:Java TimerService.createTimer方法的具体用法?Java TimerService.createTimer怎么用?Java TimerService.createTimer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ejb.TimerService
的用法示例。
在下文中一共展示了TimerService.createTimer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fireInThirtySeconds
import javax.ejb.TimerService; //导入方法依赖的package包/类
@Override
public void fireInThirtySeconds() throws EJBException {
TimerService theTimerService = theEJBContext.getTimerService();
String aLabel = "30SecondTimeout";
Timer theTimer = theTimerService.createTimer(300, aLabel);
logger.info("timer is: " + theTimer);
}
示例2: createCronJob
import javax.ejb.TimerService; //导入方法依赖的package包/类
public void createCronJob() {
Long intervall = 10 * 1000L;
String value;
try {
value = configService
.getValue(LocationSanityBusiness.class, contextService.getCallersUser()
.getClient(), LocationSanityBusiness.TIME_OUT_KEY);
if (value != null) {
try {
intervall = Long.parseLong(value);
} catch (NumberFormatException ex) {
log.warn(ex.getMessage());
intervall = 10 * 1000L;
}
}
} catch (EntityNotFoundException e) {
log.error(e.getMessage(), e);
}
if (getTimer() != null){
cancelCronJob();
}
TimerService timerService = ctx.getTimerService();
timerService.createTimer(new Date(System.currentTimeMillis() + intervall), intervall,
LocationSanityBusiness.TIME_OUT_INFO);
}
示例3: createTimerWithInterval
import javax.ejb.TimerService; //导入方法依赖的package包/类
private void createTimerWithInterval(TimerService timerService,
TimerType timerType, long timerInterval, long timerOffset)
throws ValidationException {
// FIXME: this is quick fix for bug 11241. To avoid generate the
// same constraint of timer, set timerInterval to
// TIMER_HANDLING_DISTANCE if the timerInterval is smaller than
// TIMER_HANDLING_DISTANCE.
if (timerInterval <= TIMER_HANDLING_DISTANCE) {
timerInterval = TIMER_HANDLING_DISTANCE;
}
Date nextStart = getDateForNextTimerExpiration(timerInterval,
timerOffset);
ValidationException validationException;
String[] params;
if (nextStart.getTime() < 0) {
if (timerType.name().equals(TimerType.USER_NUM_CHECK.name())) {
params = new String[] { timerType.name(),
timerType.getKeyForIntervalTime().name() };
validationException = new ValidationException(
ValidationException.ReasonEnum.TIMER_USERCOUNT_EXPIRATIONDATE_INVALID,
null, params);
logger.logError(
Log4jLogger.SYSTEM_LOG,
validationException,
LogMessageIdentifier.ERROR_TIMER_USERCOUNT_EXPIRATIONDATE_INVALID,
params);
} else {
params = new String[] { timerType.name(),
timerType.getKeyForIntervalTime().name(),
timerType.getKeyForIntervalOffset().name() };
validationException = new ValidationException(
ValidationException.ReasonEnum.TIMER_EXPIRATIONDATE_INVALID,
null, params);
logger.logError(
Log4jLogger.SYSTEM_LOG,
validationException,
LogMessageIdentifier.ERROR_TIMER_EXPIRATIONDATE_INVALID,
params);
}
throw validationException;
}
cancelObsoleteTimer(timerService, timerType);
timerService.createTimer(nextStart, timerInterval, timerType);
SimpleDateFormat sdf = new SimpleDateFormat();
logger.logInfo(Log4jLogger.SYSTEM_LOG,
LogMessageIdentifier.INFO_TIMER_CREATED_WITH_INTERVAL,
timerType.toString(), sdf.format(nextStart),
Long.toString(timerInterval));
}