我做错了吗?
import java.util.Date;
import java.util.Timer;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.LocalBean;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.TimerService;
@Singleton
@LocalBean
@Startup
public class CIScheduler {
@Resource
private TimerService timerService;
@PostConstruct
public void init() {
timerService.createTimer(1000, 5000, "myTimerInterval");
}
@Timeout
public void execute(Timer timer) {
System.out.println("Current Time : " + new Date());
}
}
Stack:JDK 8,Wildfly 10
错误日志:
09:31:31,781 WARN [org.jboss.as.ejb3](EJB默认值 - 9)WFLYEJB0161: 无法恢复计时器' config-api.config-api.CIScheduler' (id = f571b03a-efa 9-467d-a9de-b17d88bf54c7)来自其持久状态 09:31:31,783 ERROR [org.jboss.as.ejb3](EJB默认值 - 9)WFLYEJB0022: 计时器重试超时错误: [id = 35f55f82-a982-43d8-bece-42cfc89debe8 timedObj ectId = config-api.config-api.CIScheduler auto-timer ?: false persistent ?:真正 timerService=org.jboss.as.ejb3.timerservice.TimerServiceImpl@1eef0fd init ialExpiration = Wed Jun 15 09:20:46 BRT 2016 intervalDuration(in milli sec)= 5000 n extExpiration = Wed Jun 15 09:31:36 BRT 2016 timerState = RETRY_TIMEOUT info = myTimer Interval]: javax.ejb.EJBException:java.lang.IllegalArgumentException:ja va.lang.ClassCastException@1da01b2
从https://examples.javacodegeeks.com/enterprise-java/ejb3/timer/ejb-timer-service-example/
中提取的样本更新:我清理了数据和tmp文件夹,错误日志更改为:
09:49:42,178 INFO [org.jboss.as.ejb3](EJB默认值 - 2)WFLYEJB0021: 计时器:[id = 26b74afb-625d-4007-a786-1c0caa92a70b timedObjectId = configuracao-api.config-api.CIScheduler auto-timer?:false persistent?:true timerService = org.jboss.as.e jb3.timerservice.TimerServiceImpl@1b701e2 initialExpiration = Wed Jun 15 09:49:37 BRT 2016 intervalDuration(以毫秒为单位)= 5000 nextExpiration = Wed Jun 15 09:49:47 BRT 2016 timerState = IN_TIMEOUT info = myTimerInterval]将重试09:49:42,179 INFO [org.jboss.as.ejb3](EJB默认值 - 2)WFLYEJB0023:重试t imeout 对于计时器:[id = 26b74afb-625d-4007-a786-1c0caa92a70b timedObjectId = CONFIG-api.config-api.CIScheduler auto-timer?:false persistent?:true timerS ervice=org.jboss.as.ejb3.timerservice.TimerServiceImpl@1b701e2 initialExpiration = Wed Jun 15 09:49:37 BRT 2016 intervalDuration(以毫秒为单位)= 5000 nextExpiration = Wed Jun 15 09:49:47 BRT 2016 timerState = IN_TIMEOUT info = myTimerInterval] 09:49:42,181 ERROR [org.jboss.as.ejb3](EJB 默认 - 2)WFLYEJB0022:计时器重试超时错误: [id = 26b74afb-625d-4007-a786-1c0caa92a70b timedObj ectId = config-api.config-api.CIScheduler auto-timer?:false 持久?:是的 timerService=org.jboss.as.ejb3.timerservice.TimerServiceImpl@1b701e2 init ialExpiration = Wed Jun 15 09:49:37 BRT 2016 intervalDuration(in milli sec)= 5000 n extExpiration = Wed Jun 15 09:49:47 BRT 2016 timerState = RETRY_TIMEOUT info = myTimer Interval]: javax.ejb.EJBException:java.lang.IllegalArgumentException:参数 类型不匹配 at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInt erceptor.java:187) .......
答案 0 :(得分:2)
使用@Timeout注释的方法只允许使用类型为javax.ejb.Timer的参数。您无意中从util包(java.util.Timer)导入了Timer。如果您修复导入,计时器应该像魅力一样:)。
答案 1 :(得分:0)
要解决该问题,您必须执行一些步骤:
@Schedule
在您的wildfly服务器上转到以下路径:wildfly-13.0.0.Final/standalone/data/timer-service-data/
并删除您的内容,例如:eSocialWeb-1.0-SNAPSHOT.eSocialWeb-1.0-SNAPSHOT.ESocialTimer
。
再次部署您的战争或罐子或耳朵并微笑!
结果,除非您在计时器@Schedule
中进行了更改,否则您再也不会看到此消息:
[org.jboss.as.ejb3.timer] (ServerService Thread Pool -- 92) WFLYEJB0161: Failed to reinstate timer 'eSocialWeb-1.0-SNAPSHOT.eSocialWeb-1.0-SNAPSHOT.ESocialTimer'