Using OJB with JCS.

This page will explain you in 4 steps how to configure Apache JCS as Object Cache for OJB in Cocoon.




I think it works in any configuration, but just in case, here isthe tested platform:


Let your servlet breathe calm

My first attempt to setup this configuration failed because of a OutOfMemoryError. The problem showed to be that the servlet does not had enough memory to run. ie: add this lines in

# Set Java Options
JAVA_OPTS='-Xms32m -Xmx128m'
if [ -r "$JAVA_OPTS"/bin/ ]; then
  . "$JAVA_OPTS"/bin/

Tell OJB to use JCS

In your file, find the Object Cache section. Comment the line where is ObjectCacheDefaultImpl and uncomment the line where is ObjectCacheJCSPerClassImpl. ie:

# Object cache

Tell Cocoon that OJB will use JCS

Cocoon is shipped with a default JCS configuration. Cocoon allow to define new cache regions for JCS via cocoon.xconf. We need to configure the default region used by the JCS ObjectCache implementation for OJB. Search <store> and add this parameters:

<store logger="">
    <parameter name="maxobjects" value="10000"/>
    <parameter name="use-cache-directory" value="true"/>
    <parameter name="jcs.region.ojbDefault" value="DC"/>
    <parameter name="jcs.region.ojbDefault.cacheattributes"
    <parameter name="jcs.region.ojbDefault.cacheattributes.MaxObjects" value="1000"/>
    <parameter name="jcs.region.ojbDefault.cacheattributes.MemoryCacheName"

The last 4 parameters (starting with jcs.region.ojbDefault) define the cache region that OJB will use. You can tell JCS how many OJB Object will be able to cache by changing the value of the parameter jcs.region.ojbDefault.cacheattributes.MaxObjects

That is all!

Now restart Tomcat and start to use JCS. You will notice a performance improvement. Good Luck!

More info:

-- AntonioGallardo

UsingOJBWithJCS (last edited 2009-09-20 23:42:51 by localhost)