If I have a static fields in a stateless 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?
EDIT Mark the field as final as suggested bellow.
Yes, it will be shared, but only inside a single JVM of course. And its capitalization indicates that it’s a constant, and should thus be
final.If it’s not a constant, then it smells, doesn’t respect tha Java naming conventions, and violates the EJB spec.