Java 将参数设置为ejb计时器任务以执行后端进程
我使用Java 将参数设置为ejb计时器任务以执行后端进程,java,ejb-3.1,timertask,Java,Ejb 3.1,Timertask,我使用EJB定时器任务对数据库执行定期服务查询,并在特定时间内将更新发送给客户端。此期间由客户定义。 我将客户机请求传递给ejb计时器无状态会话bean。请求存储为实例变量 当我通过JNDI调用timer任务时,我将客户机请求设置为这个实例变量及其在timerService.createTimer()调用之前可用。但是当@Timeout发生时,实例变量为null 我需要这个客户端请求来执行DB查询以查找请求参数 @Stateless public class PeriodicService i
EJB定时器
任务对数据库
执行定期服务查询,并在特定时间内将更新发送给客户端。此期间由客户定义。
我将客户机
请求
传递给ejb
计时器
无状态
会话bean
。请求
存储为实例变量
当我通过JNDI调用timer任务时,我将客户机请求设置为这个实例变量
及其在timerService.createTimer()调用之前可用。但是当@Timeout发生时,实例变量
为null
我需要这个客户端请求来执行DB查询以查找请求参数
@Stateless
public class PeriodicService implements TimerRemote{
@Override
public void initializeTimer(Date firstDate, long timeout, String info) throws RemoteException {
try {
// below line show the request is not null.
System.out.println("request in initializeTimer "+this.request);
// create onetime service now.
timerService.createTimer(firstDate, info);
log.info("Timer created at " + firstDate + " with info: " + info);
} catch (Exception e) {
log.fatal("Exception after create timer : "+ e.toString());
e.printStackTrace();
}
}
@Timeout
public void ejbTimeout(Timer arg0) {
// below line show the requst as null
log.debug("Request in ejbTimeout "+this.request);
}
public void setRequest(IVEFRequest request) {
this.request = request;
}
private IVEFRequest request = null;
}
我不熟悉EJB
。我做错了什么事?或者,我如何保持请求变量可用,直到我取消/停止计时器你可以在下面的代码中尝试,无需创建单独的实例变量
在创建计时器时,提供要在timeout方法中接收的对象
timerService.createTimer(firstDate, request);
然后,在timeout方法中获取在创建计时器时传递的对象
(IVEFRequest)arg0.getInfo();
那我怎么取消计时器呢?我使用信息部分来识别计时器。但是如果我用它来传递请求,那么当我想取消计时器时,我怎么能取消它呢?@user2771655你不能从请求对象本身确定要取消哪一个吗?如果不能,那么向它添加所需的信息。否则它可以保存任何对象类型。因此,您可以在地图中添加请求+信息并将其传递,然后您可以同时拥有这两种信息。