Search code examples
javajakarta-eeejb

Is it ok to have static final map in stateless ejb to save sate?


Stateless EJB's should not have non-final static fields that are used to save state because this does not work in distributed apps with more that one JVM. But if we have a static final Map in EJB to save a few parameters about our distributed applications state is that ok and will the updates on the map be visible to applications running on separate JVMs?


Solution

  • The whole point behind Stateless EJBS is that they are cheap because they don't need to be replicated in a distributed environment.

    Therefore any state changes in your static final Map will not be replicated.

    You would be better off using a distributed cache such as EhCache, Infinispan or even memcache for this purpose.