You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by Miguel A Paraz <mp...@gmail.com> on 2005/08/03 17:13:12 UTC
GBeans threading best practices
Hi,
I'm planning on writing my own GBeans to implement services.
Is it OK to start new Threads - using new Thread() directly, or
indirectly by using util.concurrent facilities which I see in the
code?
Geronimo won't know about them and it's up to the GBean to shut them
down in doStop().
Re: GBeans threading best practices
Posted by Dain Sundstrom <da...@iq80.com>.
On Aug 3, 2005, at 9:34 AM, Dain Sundstrom wrote:
> On Aug 3, 2005, at 8:13 AM, Miguel A Paraz wrote:
>
>
>
>> Hi,
>> I'm planning on writing my own GBeans to implement services.
>>
>> Is it OK to start new Threads - using new Thread() directly, or
>> indirectly by using util.concurrent facilities which I see in the
>> code?
>>
>>
>
> You can start threads directly, but it is preferrable to use a
> EDU.oswego.cs.dl.util.concurrent.Executor. The best practice is to
> have the Executor inject via constructor injection or setter
> injection. This allows a user of your service to have complete
> control the properties of the thread pool.
>
Let me be a bit more clear. I suggest you write your code to use the
concurrent executor since it is common reusable api with many
implementations. When it comes to deploying your service in
Geronimo, the Geronimo ThreadPool class implements the Executor so
you can just use that service with a Geronimo GBean reference.
-dain
Re: GBeans threading best practices
Posted by Dain Sundstrom <da...@iq80.com>.
On Aug 3, 2005, at 8:13 AM, Miguel A Paraz wrote:
> Hi,
> I'm planning on writing my own GBeans to implement services.
>
> Is it OK to start new Threads - using new Thread() directly, or
> indirectly by using util.concurrent facilities which I see in the
> code?
You can start threads directly, but it is preferrable to use a
EDU.oswego.cs.dl.util.concurrent.Executor. The best practice is to
have the Executor inject via constructor injection or setter
injection. This allows a user of your service to have complete
control the properties of the thread pool.
> Geronimo won't know about them and it's up to the GBean to shut them
> down in doStop().
Yes
-dain
Re: GBeans threading best practices
Posted by David Jencks <da...@yahoo.com>.
It's OK, but as a design principle I strongly recommend you use a
separate thread pool. We have a couple already and there are plans for
a good one on the way :-)
The simplest is the DefaultThreadPool or
org.apache.geronimo.pool.ThreadPool class. An example of using from a
gbean is the timer service in the timer module. A gbean configuration
for it is in the system-database-plan.xml and looks like this:
<gbean name="JDBCTransactionalThreadPooledTimer"
class="org.apache.geronimo.timer.jdbc.JDBCStoreThreadPooledTransactional
Timer">
<attribute name="repeatCount">5</attribute>
<reference
name="TransactionContextManager"><moduleType>J2EEModule</
moduleType><module>org/apache/geronimo/Server</
module><name>TransactionContextManager</name></reference>
<reference
name="ManagedConnectionFactoryWrapper"><moduleType>JCAResource</
moduleType><name>SystemDatasource</name></reference>
<reference
name="ThreadPool"><moduleType>J2EEModule</moduleType><module>org/
apache/geronimo/Server</module><name>DefaultThreadPool</name></
reference>
<!--TODO remove moduleType when gbeans get the moduleType of
the plan they are in -->
<reference
name="DerbySystem"><moduleType>J2EEModule</
moduleType><name>DerbySystem</name></reference>
</gbean>
Note the reference to the thread pool.
thanks
david jencks
On Aug 3, 2005, at 8:13 AM, Miguel A Paraz wrote:
> Hi,
> I'm planning on writing my own GBeans to implement services.
>
> Is it OK to start new Threads - using new Thread() directly, or
> indirectly by using util.concurrent facilities which I see in the
> code?
>
> Geronimo won't know about them and it's up to the GBean to shut them
> down in doStop().
>