You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Stephen McConnell <mc...@apache.org> on 2002/08/15 04:50:47 UTC

ThreadLocalLifestyleHandler.java


bloritsch@apache.org wrote:

>  /**
>   * Lifestyle implementation that provides suppport for the per thread
>   * policy.  Request for a single instance will allways return the
>   * same instance for each request.
>   *
>   * NOTE:  Need to register a listener for threaddeath so I can properly
>   *        dispose of the component when the associated thread dies.
>   *
>   * NOTE 2: This is untested.
>   *
>  
>

Berlin:

Looking good!

Here is a log of four instances of the "simple" component, each running 
in a seperate container (therefor each in a seperate thread) except for 
the "simple" and "simpleX" component which share the same container. 
 I'm printing out the identity hashcode of a single lifecycle extension 
that is extending all of these components.  The lifecycle extension has 
been declared with a "thread" lifestyle policy.  

As you can see - the instance is only being created in in a new thread.  

Cheers, Steve.


[INFO   ] (root.simple#23503403): create id: 7841785, 
Thread[Thread-2,5,main]
[INFO   ] (root.simple#23503403): access id: 7841785, 
Thread[Thread-2,5,main]
[INFO   ] (root.sub.demo.simple): create id: 813251, Thread[Thread-4,5,main]
[INFO   ] (root.sub.demo.simple): access id: 813251, Thread[Thread-4,5,main]
[INFO   ] (root.sub.demo.simpleX): create id: 813251, 
Thread[Thread-4,5,main]
[INFO   ] (root.sub.demo.simpleX): access id: 813251, 
Thread[Thread-4,5,main]
[INFO   ] (root.sub.demo.working.admin.simple2): create id: 31538514, 
Thread[Thread-9,5,main]
[INFO   ] (root.sub.demo.working.admin.simple2): access id: 31538514, 
Thread[Thread-9,5,main]
[INFO   ] (root.sub.demo.simple): release id: 813251, 
Thread[Thread-4,5,main]
[INFO   ] (root.sub.demo.simple): destroy id: 813251, 
Thread[Thread-4,5,main]
[INFO   ] (root.sub.demo.simpleX): release id: 813251, 
Thread[Thread-4,5,main]
[INFO   ] (root.sub.demo.simpleX): destroy id: 813251, 
Thread[Thread-4,5,main]
[INFO   ] (root.sub.demo.working.admin.simple2): destroy id: 31538514, 
Thread[Thread-9,5,main]
[INFO   ] (root.simple#23503403): release id: 7841785, 
Thread[Thread-2,5,main]
[INFO   ] (root.simple#23503403): destroy id: 7841785, 
Thread[Thread-2,5,main]


>

-- 

Stephen J. McConnell

OSM SARL
digital products for a global economy
mailto:mcconnell@osm.net
http://www.osm.net




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: ThreadLocalLifestyleHandler.java

Posted by Berin Loritsch <bl...@apache.org>.
> From: Stephen McConnell [mailto:mcconnell@apache.org] 
> 
> bloritsch@apache.org wrote:
> 
> >  /**
> >   * Lifestyle implementation that provides suppport for the 
> per thread
> >   * policy.  Request for a single instance will allways return the
> >   * same instance for each request.
> >   *
> >   * NOTE:  Need to register a listener for threaddeath so I 
> can properly
> >   *        dispose of the component when the associated thread dies.
> >   *
> >   * NOTE 2: This is untested.
> >   *
> >  
> >
> 
> Berlin:

Berin (no 'l') ;)

> 
> Looking good!

Thanks.

> 
> Here is a log of four instances of the "simple" component, 
> each running 
> in a seperate container (therefor each in a seperate thread) 
> except for 
> the "simple" and "simpleX" component which share the same container. 
>  I'm printing out the identity hashcode of a single lifecycle 
> extension 
> that is extending all of these components.  The lifecycle 
> extension has 
> been declared with a "thread" lifestyle policy.  
> 
> As you can see - the instance is only being created in in a 
> new thread.  

The only problem is that it is not being destroyed--properly--
with the thread.  A better alternative may to create a proxy
that takes advantage of the finalize() method.  It will cycle
the component through the destroy lifecycle.

As to the MPool implementation, we need a CommandQueue and the
PoolManager.  I would prefer to place the CommandQueue and the
PoolManager in either the kernel or some other container--otherwise
we have a new copy for each component, which is not ideal.

I would be happy to hear any suggestions on how to handle that.
My ContainerManager sets those up, and then it passes it to the
container.

> 
> Cheers, Steve.
> 
> 
> [INFO   ] (root.simple#23503403): create id: 7841785, 
> Thread[Thread-2,5,main]
> [INFO   ] (root.simple#23503403): access id: 7841785, 
> Thread[Thread-2,5,main]
> [INFO   ] (root.sub.demo.simple): create id: 813251, 
> Thread[Thread-4,5,main]
> [INFO   ] (root.sub.demo.simple): access id: 813251, 
> Thread[Thread-4,5,main]
> [INFO   ] (root.sub.demo.simpleX): create id: 813251, 
> Thread[Thread-4,5,main]
> [INFO   ] (root.sub.demo.simpleX): access id: 813251, 
> Thread[Thread-4,5,main]
> [INFO   ] (root.sub.demo.working.admin.simple2): create id: 31538514, 
> Thread[Thread-9,5,main]
> [INFO   ] (root.sub.demo.working.admin.simple2): access id: 31538514, 
> Thread[Thread-9,5,main]
> [INFO   ] (root.sub.demo.simple): release id: 813251, 
> Thread[Thread-4,5,main]
> [INFO   ] (root.sub.demo.simple): destroy id: 813251, 
> Thread[Thread-4,5,main]
> [INFO   ] (root.sub.demo.simpleX): release id: 813251, 
> Thread[Thread-4,5,main]
> [INFO   ] (root.sub.demo.simpleX): destroy id: 813251, 
> Thread[Thread-4,5,main]
> [INFO   ] (root.sub.demo.working.admin.simple2): destroy id: 
> 31538514, 
> Thread[Thread-9,5,main]
> [INFO   ] (root.simple#23503403): release id: 7841785, 
> Thread[Thread-2,5,main]
> [INFO   ] (root.simple#23503403): destroy id: 7841785, 
> Thread[Thread-2,5,main]
> 
> 
> >
> 
> -- 
> 
> Stephen J. McConnell
> 
> OSM SARL
> digital products for a global economy
> mailto:mcconnell@osm.net
> http://www.osm.net
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:avalon-dev-> unsubscribe@jakarta.apache.org>
> For 
> additional commands, 
> e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>