@Asynchronous call for @Stateful
suikast42 Jan 31, 2012 7:13 AMHi Friends,
I have a problem with the @Asynchronous method call on satefull beans. If my bean is stateless and my asynchronous method computes long time then the container will create a new instance on next call from the client right ?
So I have a Singletonbean which hold references on some Statefull beans. When I call an asynchronous methods of my statefull beans in a sequence then the first computation blocks the rest.
What I assume is that the bean instaces start the comutation parallel. But the real behavior isn't so.
My Sigletom
@Startup
@Singleton
public class SingletonTest implements SingletonTestLocal {
@EJB
StateFullTestLocal statefulTest1;
@EJB
StateFullTestLocal statefulTest2;
@EJB
StateFullTestLocal statefulTest3;
@EJB
StateFullTestLocal statefulTest4;
@Resource
TimerService timerService;
Logger lLog = Logger.getLogger(SingletonTest.class);
@SuppressWarnings("unused")
@PostConstruct
private void init(){
createTimer(UUID.randomUUID(), 5000);
}
@SuppressWarnings("unused")
@Timeout
private void timeOut(Timer timer){
lLog.debug("TIMER START");
statefulTest1.testAsync();
statefulTest2.testAsync();
statefulTest3.testAsync();
statefulTest4.testAsync();
lLog.debug("TIMER END");
}
public void createTimer(UUID beanID, long intervallTime){
TimerConfig config = new TimerConfig(beanID, false);
timerService.createIntervalTimer(1000, intervallTime, config);
}
}
My Stateful
@Stateful
@LocalBean
public class StateFullTest implements StateFullTestLocal {
Logger log = Logger.getLogger(StateFullTest.class); ;
@EJB
SingletonTestLocal singletonTest;
@PostConstruct
public void init(){
log.debug("PostConstruct");
}
@Override
@Asynchronous
public void testAsync(){
log.info("Start " + hashCode());
while (true) {
}
}
My Consoleoutput
13:11:12,802 DEBUG [StateFullTest] PostConstruct
13:11:12,802 DEBUG [StateFullTest] PostConstruct
13:11:12,802 DEBUG [StateFullTest] PostConstruct
13:11:12,802 DEBUG [StateFullTest] PostConstruct
13:11:13,880 DEBUG [SingletonTest] TIMER START
13:11:13,911 DEBUG [SingletonTest] TIMER END
13:11:13,927 INFO [StateFullTest] Start 29639543
The other instances are not triggerd.
So what do I wrong ??