Stateful EJB Lifecycle question
I have the following bean declaration:
@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;
}
}
I'm trying to understand the Stateful EJB Lifecycle. Once the state of this EJB is permanently modified using the interrupt() method, and all references to this instance are set to null, is the bean instance put back in the eligible pool or is it discarded?
What makes me question my judgement is the TransactionAttributeType.NOT_SUPPORTED. I would hope the container spec says somewhere that a Stateful EJB is reset somehow how to it's initial state before 开发者_StackOverflow中文版being used again, not matter what the TransactionAttributeType is.
Thanks!
Read 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.
If nobody ever calls an @Remove method, the container will wait antil a timeout is reached and remove it.
The @TransactionAttribute
annotation has nothing to do with the bean's lifecycle. It only tells the container if and when a transaction should be started when one of its business methods is invoked.
@cj91
I am not sure whether the SPEC specifically says what you are asking, i,e
I would hope the container spec says somewhere that a Stateful EJB is reset somehow how to it's initial state before being used again, not matter what the TransactionAttributeType is.
But I am pretty sure that the transaction attribute type has no impact on how a stateful EJB is (re)initialized.
NOT_SUPPORTED just means that the method cannot be invoked from within a transaction context. If it is invoked, it is silently ignored.
See
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Transaction3.html
精彩评论