java - 定时器服务 : Bean does not have timers in EJB3. 1

标签 java websphere ejb-3.1

实际上,我正在将应用程序从 EJB2.1 迁移到 EJB3.1。更改应用程序后,我在调用 getTimers() 方法时遇到问题。

我正在使用 Websphere 服务器。

这是我的代码:

@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class TimedRequestBean implements TimedRequestLocal {    
    @Resource
    private SessionContext sessionContext;
    public void cancelTimers() {
            TimerService ts = this.sessionContext.getTimerService();
            Collection timers = ts.getTimers();
            Iterator it = timers.iterator();
            while (it.hasNext()) {
                Timer myTimer = (Timer)it.next();
                myTimer.cancel();
            }
       }
}

日志:

javax.ejb.EJBException: See nested exception; nested exception is: java.lang.IllegalStateException: Timer Service: Bean does not have timers: BeanId(LeadDeliverySystemEAR#timedrequest.jar#TimedRequestBean, null) java.lang.IllegalStateException: Timer Service: Bean does not have timers: BeanId(LeadDeliverySystemEAR#timedrequest.jar#TimedRequestBean, null) at com.ibm.ejs.container.BeanO.getTimers(BeanO.java:1733) at com.ford.it.request.async.TimedRequestBean.cancelTimers(TimedRequestBean.java:460)

最佳答案

如果 Bean 尚未声明为具有任何计时器,

TimerService.getTimers() 将引发 IllegalStateException。为了避免这种情况,bean 必须使用 @Scheulde 来声明自动计时器,或使用 @Timeout 来声明编程计时器的超时回调方法(或者两者的 XML 等效项)注释)。

基本上,不可能有计时器的 bean 无法访问 TimerService。由于没有@Timeout方法,因此不能在TimerService上调用任何创建方法;同样,由于该 bean 不存在计时器,因此也不允许调用 getTimers()

关于java - 定时器服务 : Bean does not have timers in EJB3. 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55813354/

相关文章:

java - 由于 "cannot find annotation method name() in type javax.persistence.Table"编译错误

java - Spring 和 MongoDB Atlas 在 5 分钟不活动后中断连接

tomcat - 如何从 IBM Websphere 迁移到 Tomcat?

java - JPA 插入和更新

java - 使用 context.lookup 加载远程接口(interface)时出现问题

java - android.widget.TextView 与 TextView

java - ProcessWindowFunction<IN, OUT, KEY, W> 上的 Flink 单元测试

java - 从 WebSphere 8 运行 Java 8 MQ 应用程序时出错

java - 如何从Websphere的标准输出日志中找出Web服务器模块使用了哪个端口?

java - 我可以从同一 EJB 中具有 TransactionAttributeType.NOT_SUPPORTED 的另一个方法调用具有 TransactionAttributeType.REQUIRED 的方法吗