Caching data from database on a java collaboration

Hi

I implement cache in a java collaboration working with HashMaps. When the first message arrive to java colaboration, this message ititialize a HashMap, the next message use that cache for looking neccesary data.

But when the first message arrive, it take any seconds for initializing hashmap.

I want use static initializers for doing that.

How can I do it?

Thanks on advanced.

Hector

[431 byte] By [conectora] at [2007-11-26 12:26:45]
# 1

Hi Hector.

The JCD is implemented as a session EJB. As far as I can judge from the deployment descriptor, this is a stateless EJB, which means that caching anything in it is unreliable. The next JCD call can go to other instance of EJB and the first instance may be purged and your cache will disappear.

Taken from ejb-jar.xml

<enterprise-beans >

<session>

<description></description>

<display-name></display-name>

<ejb-name>cmCGPServices_jcdGetAccounts1_XSDService</ejb-name>

<local-home>com.stc.codegen.framework.runtime.DeployedServiceHome</local-home>

<local>com.stc.codegen.framework.runtime.DeployedServiceLocal</local>

<ejb-class>com.stc.codegen.XSDImpl.runtime.ejb.XSDService</ejb-class>

<session-type>Stateless</session-type>

<transaction-type>Container</transaction-type>

</session>

So my understanding that if you want to cache something you should either write your own _stateful_ session EJB and access it from JCD or use some singleton object again written in pure Java.

Victor

sand123a at 2007-7-7 15:33:09 > top of Java-index,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...
# 2
hi *,we are sometimes using static hsahmaps as caches.as victor already said it is not reliable but works for us in a sufficient way.regards chris
Chris.Brennsteinera at 2007-7-7 15:33:09 > top of Java-index,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...
# 3
Hi, ChrisHow can I using hashmaps on static initializers, that is, how can I connect to database in a Java collaboration for caching data, before java collaboration receive the first message?ThanksHector
conectora at 2007-7-7 15:33:09 > top of Java-index,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...
# 4
hi hector,you could make a static var Hashmap mycache by private static HashMap myCache;and fill this through non static functions.i think the variable will be available as long as class loader does not collapse.regards chris
Chris.Brennsteinera at 2007-7-7 15:33:09 > top of Java-index,Java Enterprise System,Java Composite Application Platform Suite -- General Discussion...