[英]Where I can't create timer of EJB3 Timer Service?
In EJB3 Timer Service, I can create the timer with the timerService.createTimer(...)
function, but the question is where I can use it? 在EJB3计时器服务中,我可以使用
timerService.createTimer(...)
函数创建计时器,但问题是我可以在哪里使用它? As I know, I can't do it in Session Bean's lifecycle function, like @PostConstruct
function. 据我所知,我无法在Session Bean的生命周期函数(如
@PostConstruct
函数)中做到这一点。
I also read it can't be called in Stateful session bean? 我也读到它不能在有状态会话bean中调用吗? Is there anything else I should pay attention about createing timer?
创建计时器还有其他注意事项吗?
I guess the most important thing to be aware of is that timers are transactional objects; 我想最重要的是要知道定时器是事务对象。 it means, if you create a timer in a transaction that will roll back, the timer creation will be rolled back as well.
这意味着,如果您在将回滚的事务中创建计时器,则计时器创建也会被回滚。 This also implies that they must be called in a transaction context, and there is none in
@PostConstruct
. 这也意味着必须在事务上下文中调用它们,并且
@PostConstruct
没有。
Oh, and as you know, you need a TimerService to create a timer, so you usually will be using it in managed classes, so you can inject it. 哦,正如您所知道的,您需要一个TimerService来创建一个计时器,因此通常将在托管类中使用它,以便将其注入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.