What are the best pracices to persist session and cross session data in a enterprise application which can be used commonly by the servlet layer as well as the EJB Layer.Currently we are using static HashMap to store and retrieve these data which indeed are consuming lot of App Servers Heap Memory.
Static data structures cannot be used in EJBs, unless they are read only. If you've got one you'll need to get rid of it.
If your cached data is required in both tiers the sensible place to store it is in the EJB layer. To do this you have the option to
use stateful beans and redundantly replicate it
implement a distributable cache and use that
use another persistent store, such as a database
If you only need this data in the Servlet tier an easier option might be to use one of many caching mechanisms available. These are very configuable allowing you to set all the stuff you might want (max life in cache, max number objects in cache, max memory per object, max total memory, second level cache etc.) A down side would be that this cache would not work in a cluster, unless you also made it distributable.
venki sheshgiri wrote: which indeed are consuming lot of App Servers Heap Memory.
This is going to happen with any caching solution. The data needs to be stored somewhere if it's not going to be read from disk or database.
venki sheshgiri wrote:What is the best way to implement distributable cache
It's more commonly called a "distributed search." When you look for an open source or commercial one, it helps to be looking under the name people list it as. You definitely should not "implement" a distributed cache. It is complex and very difficult to get right. This list of open source Java caches list which are distributed.
venki sheshgiri wrote:[ I would like avoid scenarios where a DB Query or properties file loading are involved.
Some caches work via replication. Which does use network traffic of course, but not a DB query. I can udnerstand why you want to get a potentially expensive DB query out of the picture, but what's wrong with reading from a property file and caching that?
Not the thing I was suggesting. I was thinking along the lines of EHCache, JCA, JavaCache etc. rather than a full blown information retreival technology. If all you want to do is cache some stuff in an JEE application is an IR technology not overkill?
but what's wrong with reading from a property file and caching that?
An edge case true, but this is suspect in a cluster.
Paul,Jeanne Sorry for posting late was busy with some Crystal Report Issue.
Paul you got me why I dont want do it using a properties File. Ideally we deploy our Enterprise Application in Horizontal Cluster Setup and we need to address Server Failover,Request Hopping Scenarios between two Application Server Nodes.