• Post Reply Bookmark Topic Watch Topic
  • New Topic

why static final objects should not be used in EJB s?

 
saran sadaiyappan
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have read that static final objects is not a recommended usage in EJBs as it would pose inconsistency in clustered environments. But I am grey with what it really means. Can anyone explain it clear?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saran,
You get one "static" context for each JVM. So if you have static data that is shared between different EJB containers, there will be multiple copies of that data.

Note that it is still ok to use static final for constants in EJBs. You wouldn't want ot use static for data that changes because you wouldn't know there was a stale copy.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a cluster you can move that data out of Java memory into some shared resource like a database or look into "distributed cache" products.
 
Sanjeev Verma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add to what has been stated above by Jeanne. You can use static final constants as long as the constant points to a immutable object. If the object is mutable, then although the reference is final, the content/state of the object itself can be changed, thus creating the same issue of inconsistent state across containers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!