You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by vo...@basf-it-services.com on 2003/11/05 10:17:14 UTC

ExtendedComponentSelector not ThreadSafe

In my long debugging sessions the last days I found another issue inside
the ExtendedComponentSelector ;-)

ExtendedComponentSelector is a ThreadSafe Component which implements
ParentAware. To hold all the components which are lookup by the parent CS a
HashSet is used.

 /** The components selected in the parent selector */
    protected Set parentComponents;

Inside the select we have the following code:

try {
    return super.select(hint);

} catch(ComponentException ce) {
    // Doesn't exist here : try in parent selector
    Component component = this.parentSelector.select(hint);
    this.parentComponents.add(component);
    return component;
}


If two Threads or the same Thread lookup the same hint twice only one
reference is hold inside the HashSet and the release of the second
Component fail.

My first idea was first try to release the Component to the parent and if
fail call super.release(). In difference to the lookup a release doesn't
fail if a CM or CS can't release a Component, it only log a WARN.
A solution is using a "org.apache.commons.collections.MultiHashMap" which
in addition needs to be synchronized.

What do you think.

Volker




RE: ExtendedComponentSelector not ThreadSafe

Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Volker Schmitt wrote:
> 
> 
> If two Threads or the same Thread lookup the same hint twice only one
> reference is hold inside the HashSet and the release of the second
> Component fail.
> 
> My first idea was first try to release the Component to the parent and if
> fail call super.release(). In difference to the lookup a release doesn't
> fail if a CM or CS can't release a Component, it only log a WARN.
> A solution is using a "org.apache.commons.collections.MultiHashMap" which
> in addition needs to be synchronized.
> 
> What do you think.
> 
What about a org.apache.commons.collections.Bag ?

Carsten