Tuesday, June 28, 2011

OSB, Java Callout, static variables and classloaders

We have a huge (10,000 element) lookup table to enrich a payload.
We have tried to store it in Coherence cache and query it with XQuery, but performance is unacceptable and memory impact is huge,
also because XQuery doesn't allow you to create indexes on a XML document for fast searches (correct me if I am wrong).

So we are thinking of storing the whole table in a Java class as a:
static HashMap<String, XmlObject> cache = new HashMap<String, XmlObject>();

where the String is a unique key for the table (an id).

and when I need a specific element I use a lookup:

public static XmlObject lookupElement(String id) {
return cache.get(id);
}

We initialize the cache with a static init(XmlObject[] objectsToCache).

My question is:
the Java class we use as a cache container will not be garbage collected at some point in time, leaving us with no cache at all?
Also, if this Java class is accessed within a Proxy Service which is implemented as a MDB (an independent Enterprise application deployed in WebLogic with a ejb.jar module),
the classloader will not be different, hence a new instance of the class will be accessed?

My guess is that all other Proxy Services - I mean other than MDBs - are "deployed" - in fact interpreted at runtime - in the same Enterprise Application as ALSB Routing (or some other EAR starting with ALSB)...

If you deem too risky this approach of using static variables in a Java class as cache containers, which other pattern can I use?
This solution seems extremely fast.... performance is a great concern here. We cannot afford to have to marshal/unmarshal stuff or making a service invocation for each lookup.

If anybody can help, I would be grateful ( see also my post http://forums.oracle.com/forums/message.jspa?messageID=9690744#9690744 )
Thank you soooo much!
pierre




No comments: