From MZ Notes: An enterprise bean must not use read/write static fields. Using read-only static fields is allowed. Therefore, it is recommended that all static fields in the enterprise bean class be declared as final. This rule is required to ensure consistent runtime semantics because while some EJB containers may use a single JVM to execute all enterprise bean's instances, others may distribute the instances across multiple JVMs.
I used static fields to read and write data into it inside the Stateless Session bean and it worked fine. Does this mean aboove statements from MZ notes are incorrect? Am i missing something? Please exaplain ?
statement from MZ notes is absolutely correct (see core spec 21.1.2). Your observation only means that writing static variables works in your special situation (app server, bean code, and so on). But it isn't portable: If you switch to another app server you can't be sure that it works there too, or if, that it works in the same way. [ November 26, 2008: Message edited by: Ralph Jaus ]
using not final static field is not only it is not portable but also it is not distributable. that means your app in clustered environment will behave unpredictable manner. keep in mind that changing the value of a static field will effect only to the particular server but not to others in same cluster since static fields are not it shared memory.
actually I think sun should implement a proper way to come across this issue/requirement.something like application level attributes in servlet