http://docs.oracle.com/javaee/6/tutorial/doc/gipjg.html” rel=“nofollow” http://docs.oracle.com/javaee/6/tutorial/doc/gipjg.html:
无国籍者
A stateless session bean does not maintain a
conversational state with the client. When a client invokes the
methods of a stateless bean, the bean’s instance variables may contain
a state specific to that client but only for the duration of the
invocation. When the method is finished, the client-specific state
should not be retained. Clients may, however, change the state of
instance variables in pooled stateless beans, and this state is held
over to the next invocation of the pooled stateless bean. Except
during method invocation, all instances of a stateless bean are
equivalent, allowing the EJB container to assign an instance to any
client. That is, the state of a stateless session bean should apply
across all clients.
我不是EE的一位专家,但从技术上来说,这让我也能够利用田地规划。
我假定,你有,以确保每条新方法的电话都更新,而且我认为你 should确保你在方法结束后删除提及内容,以确保你不会阻止旧物体的垃圾收集,因为有些“旧的”豆类仍然保留在某些池里。
我建议这样的模式:
public class MyBean{
private SomeClass firstObject;
private SomeOtherClass anotherObject;
private AndAnotherClass thirdObject;
public void theMethod(firstObject, anotherObject, thirdObject){
try {
this.firstObject = firstObject;
this.anotherObject = anotherObject;
this.third = thirdObject;
startProcessing();
}finally {
this.firstObject = null;
this.anotherObject = null;
this.third = null;
}
}
private void startProcessing() {
doStep1();
doStep2();
doStep3();
}
[...]
}
仍然有许多法典——但如果你坚持这种风格,你就会自动跳出“Method”部分,并继续在“Processing”上读,你在“Processing”上做了一切明确而没有参数。