Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stateless Session Bean variables static or non-static.

 
mallika shah
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,

Should the variables in Stateless session beans be satic or non-static?

thanks,
mallika
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If they are static, they cannot be final.
 
Benoît de Chateauvieux
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mallika Shah,

The answer is in the EJB3 specs 21.1.2:
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.

Hope this helps,

Beno�t
 
mallika shah
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Benoit.

You have cleared my doubt..read the point from specs which you mentioned..
Also the same thing is mentioned in Pro EJB 3 -

For Stateless Session beans,static fileds should not be used,primarily because of bean redeployment issues..

As written in EJB specs, does that mean-"FOR ALL THE KINDS OF BEANS WHETHER SESSION , MDB" that if the beans use static fields , they should be declared FINAL.?

thanks for the prompt reply ,
mallika
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic