In EJB3 Timer Service, I can create the timer with the timerService.createTimer(...)
function, but the question is where I can use it?
As I know, I can't do it in Session Bean's lifecycle function, like @PostConstruct
function.
I also read it can't be called in Stateful session 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
.
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.