简体   繁体   English

无状态会话bean中的静态字段

[英]Static fields in stateless session beans

If I have a static fields in a stateless bean : 如果我在无状态bean中有一个静态字段:

@Stateless
@Local(SomeClass.class)
public class AccountBean implements SomeClass{

   private static final int STATIC_FIELD = 0;

   public AccountBean () {}
}

Will the STATIC_FIELD value be shared in all AccountBean instances, like in basic classes? 是否会在所有AccountBean实例中共享STATIC_FIELD值,就像在基本类中一样?

EDIT Mark the field as final as suggested bellow. 编辑将该字段标记为final ,如下所示。

Yes, it will be shared, but only inside a single JVM of course. 是的,它将被共享,但当然只在一个JVM内部。 And its capitalization indicates that it's a constant, and should thus be final . 它的大小写表明它是一个常数,因此应该是final

If it's not a constant, then it smells, doesn't respect tha Java naming conventions, and violates the EJB spec. 如果它不是常量,那么它会闻起来,不尊重Java命名约定,并且违反了EJB规范。

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

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