cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Mazzocchi <stef...@apache.org>
Subject Re: Memory Store and JDK 1.2
Date Tue, 29 Feb 2000 14:15:36 GMT
Michel Lehon wrote:
> 
> 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.

Great idea!!
 
> 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).

Ouch, this is not that useful. I like the newer system in 1.7 that calls
the cache-cleanup if an OutOfMemory error is caught.
 
> 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.

Hmmmm, the 1.7 MemoryStore is pretty complete on that side and yes, it
should be far better for the JVM to implement that soft references on
its own... but if the behavior is that bad, I prefer to use what we
have.
 
> For those who want to give it a try :
> You need to update you cocoon.properties
> Find the line that says 'store = org.apache.cocoon.store.MemoryStore'
> and change it to be 'store = org.apache.cocoon.store.SoftMemoryStore'
> 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.

Thank you anyway for the suggestion, I'll keep it in mind for the next
releases in case the OutOfMemory error is not solved.

> Michel Lehon.
> Michel.Lehon@Outwares.com
> SAS Data Warehousing & Web enablement.
> 
>   ------------------------------------------------------------------------
>                            Name: SoftMemoryStore.java
>    SoftMemoryStore.java    Type: Java Source File (application/x-unknown-content-type-java_auto_file)
>                        Encoding: quoted-printable


-- 
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<stefano@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------
 Come to the first official Apache Software Foundation Conference!  
------------------------- http://ApacheCon.Com ---------------------



Mime
View raw message