views:

548

answers:

2

I am using JCS to store the ldap search results which should be shared by multiple EJB. I have created a singleton class to initialize JCS only once but due to EJB's classloader, it's been initialized multiple times with its own copy. so search resources are not shared.

How are you guys resolving issue where you need to share the cache across multiple beans? I am looking for cache within JVM. (Not the remote e.g memcached etc.).

Glassfish is used as an application server.

+2  A: 

I haven't been able to test it yet, but I think that this may be the answer.

fvu
Yes, this is what I was looking for. Thx.
rjoshi
+1  A: 

Simply put, the singleton will likely "live" where your caching implementation class lives, as that's the classloader in the hierarchy that "owns" the class.

So, if each EJB is separately deployed, with their own copy of the cache lib jar, they'll each get their own copy.

If your beans are deployed in a composite EAR, sharing a single instance of the lib jar, then that cache will be shared across the beans in the EAR.

If you remove the lib from the deployment completely, and put it outside the container ($DOMAIN/lib/ext for example), then that cache will be shared by EVERYTHING in the domain (EJBs, EARs, WARs, etc.).

Will Hartung
Thanks for your answer. JCS Cache is part of common library which is shared across multiple EJB and binding components (OpenESB) but I guess $DOMAIN/lib should resolve the issues.
rjoshi