cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michel Lehon" <>
Subject Memory Store and JDK 1.2
Date Mon, 28 Feb 2000 16:49:15 GMT
Hi everyone,

Not so long ago there was a long thread about the Caching system and the
Memory Store of Cocoon...

Well a little bit after that I just got DrDobbs Journal (Feb2000, Java
Issue). In it there is a nice article
about References (Soft, Weak, Phantom). This is a new feature of JDK 1.2. It
allows you to have a reference to an object while still allowing the garbage
collector to reclaim the memory (and the object) if it runs low on memory.

I won't give much more details about the differences between these
references, some information can be found in the JDK docs (and of course in
DDJ). The only important thing is that SoftReferences are intended for
memory sensitive caches.

I thought it might be a good idea to give it a try for Cocoon.
Here is an implementation of Store that uses SoftReference to wrap the
contained objects (not the keys).
This implementation is very close the MemoryStore (in fact I started from
MemoryStore and changed a few things).

The resulting behavior is this:
The store will hold objects for the CocoonCache. Since the objects are
wrapped by a SoftReference they might be reclaimed by the garbage collector
at any time. This is good since the JVM guarantees that SoftReferences will
be cleared before throwing an OutOfMemoryException. This is good also if you
run more than one Servlet in the same JVM, allowing the cocoon cache to be
cleared if any servlet neededs more memory than available (and the heap
can't be expanded anymore).
It looks like JDK 1.2.2 under Win98 keeps all SoftReferences alive unless it
really runs out of memory, at that time it clears all SoftReferences in one
go (so the complete cache is cleared).

I know that the current JDK for Cocoon is 1.1 not 1.2.
However I though this might be useful for some user that use JDK1.2 and
still experience OutOfMemoryExceptions.
The current implementation is very simple. It could be improved by mixing it
with a classic cache algorithm.

For those who want to give it a try :
You need to update you
Find the line that says 'store ='
and change it to be 'store ='
Behavior and status is like the standard MemoryStore.

And please don't forget: JDK 1.2+ only. This has not been stress tested.

Since I don't know the procedure to submit new code, I just included it as
an attachement.
I copied the Apache Copyright notice at the top.

Michel Lehon.
SAS Data Warehousing & Web enablement.

View raw message