我有以下 bean 声明:
@Stateful
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class InteruptBean implements Interrupt {
private boolean interrupt = false;
@Override
public boolean check() {
return interrupt;
}
@Override
public void interrupt() {
interrupt = true;
}
}
我正在尝试了解有状态 EJB 生命周期。一旦使用interrupt()方法永久修改了此EJB的状态,并且对此实例的所有引用都设置为null,则该bean实例是否被放回合格池中还是被丢弃?
让我质疑自己判断的是 TransactionAttributeType.NOT_SUPPORTED。我希望容器规范在某处说明有状态 EJB 在再次使用之前以某种方式重置为初始状态,无论 TransactionAttributeType 是什么。
谢谢!
最佳答案
阅读http://download.oracle.com/javaee/6/tutorial/doc/giplj.html#gipln .
At the end of the lifecycle, the client invokes a method annotated @Remove, and the EJB container calls the method annotated @PreDestroy, if any. The bean’s instance is then ready for garbage collection.
如果没有人调用@Remove方法,容器将等待直到超时并将其删除。
@TransactionAttribute
注释与 bean 的生命周期无关。它仅在调用其业务方法之一时告诉容器是否以及何时应启动事务。
关于java - 有状态 EJB 生命周期问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6539453/