简体   繁体   English

有状态的 EJB 生命周期问题

[英]Stateful EJB Lifecycle question

I have the following bean declaration:我有以下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;
}
}

I'm trying to understand the Stateful EJB Lifecycle.我试图了解有状态的 EJB 生命周期。 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?一旦使用 interrupt() 方法永久修改了此 EJB 的 state,并且对该实例的所有引用都设置为 null,bean 实例是放回合格池中还是被丢弃?

What makes me question my judgement is the TransactionAttributeType.NOT_SUPPORTED.让我质疑我的判断的是 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 being used again, not matter what the TransactionAttributeType is.我希望容器规范在某处说明有状态 EJB 在再次使用之前以某种方式重置为初始 state,无论 TransactionAttributeType 是什么。

Thanks!谢谢!

Read http://download.oracle.com/javaee/6/tutorial/doc/giplj.html#gipln .阅读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.在生命周期结束时,客户端调用注解为@Remove 的方法,并且EJB 容器调用注解为@PreDestroy 的方法(如果有)。 The bean's instance is then ready for garbage collection.然后 bean 的实例就可以进行垃圾回收了。

If nobody ever calls an @Remove method, the container will wait antil a timeout is reached and remove it.如果没有人调用过@Remove 方法,容器将等待超时并删除它。

The @TransactionAttribute annotation has nothing to do with the bean's lifecycle. @TransactionAttribute注解与 bean 的生命周期无关。 It only tells the container if and when a transaction should be started when one of its business methods is invoked.它仅在调用其业务方法之一时告诉容器是否以及何时启动事务。

@cj91 @cj91

I am not sure whether the SPEC specifically says what you are asking, i,e我不确定 SPEC 是否明确说明了您的要求,即

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.我希望容器规范在某处说明有状态 EJB 在再次使用之前以某种方式重置为初始 state,无论 TransactionAttributeType 是什么。

But I am pretty sure that the transaction attribute type has no impact on how a stateful EJB is (re)initialized.但我很确定事务属性类型对有状态 EJB 的(重新)初始化方式没有影响。

NOT_SUPPORTED just means that the method cannot be invoked from within a transaction context. NOT_SUPPORTED 只是意味着不能从事务上下文中调用该方法。 If it is invoked, it is silently ignored.如果它被调用,它会被默默地忽略。

See

http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Transaction3.html http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Transaction3.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM