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.
Bypassing conversational state doesn't mean that a stateless session bean can't have instance variables or maintain any kind of internal state. Nothing prevents you from keeping a variable that tracks the number of times a bean instance has been called or a variable that saves data for debugging.
Annotations used in Stateless Session Bean@Stateless. @PostConstruct. @PreDestroy.
Stateless Session Beans 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.
An instance of a stateful session bean has a unique identity that is assigned by the container at create time. Stateless: A stateless session bean does not maintain conversational state. Instances of a stateless session bean have no conversational state.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With