cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <blorit...@apache.org>
Subject Re: Singleton question
Date Tue, 04 Nov 2003 13:08:00 GMT
Leszek Gawron wrote:

> I know this question should be addressed to Avalon group but I am only cocoon
> subscriber and feel much safer with you guys :)
> 
> How should I write an avalon component that is a pure singleton? The case is I
> need a component that has only ONE instance and the access is strictly
> synchronized. The component cannot be pooled because AFAIU the pool can grow
> over it's maximum size set in cocoon.xconf. 

In Cocoon 2.1 and prior you would have your component implement the ThreadSafe
interface.  In Cocoon 2.2 you would add the @x-avalon.lifstyle type="singleton"
meta tag to the JavaDoc for the class.


> 
> Normally I would implement a singleton with synchronized methods but I would
> like to make it cocoon exercise and make this a component with full lifecycle.

You can still use a "strict" singleton if you don't need access to other
components, but in servlet environments heavy use of synchronization can limit
the scalability of a system.  Of course the opposite is also true: insufficient
synchronization leads to an unstable system.  It is hard to find the right
balance, or to limit the points where you *need* synchronization.

-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


Mime
View raw message