You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2010/03/08 16:27:33 UTC

Re: [OT] Question on Executor (thread pool)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

CBy,

On 3/8/2010 7:03 AM, CBy wrote:
> My web service wraps a command-line application that is rather resource
> demanding. To manage the maximum number of instances that can run
> concurrently, it uses a (custom) thread pool.

Are you on Java 1.5+?  (If not, you should be).

If you are, you can use one of the fine implementations of executors in
java.util.concurrent, such as ThreadPoolExecutor.

> Now that I have to
> develop similar services, I would like to share the pool instead. I was
> thinking of switching to Tomcat's Executor -
> http://tomcat.apache.org/tomcat-6.0-doc/config/executor.html - but
> cannot find any examples on how to use it.

I don't believe user code has any access to Tomcat's thread pool(s). Why
not run your own thread pool(s) for this particular requirement?

> If I uncomment the corresponding lines in server.xml, can I then use the
> default tomcatThreadPool by just instantiating
> org.apache.catalina.core.StandardThreadExecutor?

Almost certainly not. You'd have to create your own
StandardThreadExecutor, configure it, and then use it. The same is true
if you were to use the Java API-provided one, except you wouldn't tie
yourself to Tomcat in that case.

> Do I have to call start() and stop() on StandardThreadExecutor or is
> this handled by Tomcat?

If you used StandardThreadExecutor, Tomcat wouldn't be managing it: you
would.

> Is it possible to block on the execute() method of StandardThreadExecutor?
> 
> Can you only have one Executor per Connector?
> 
> My current thread pool uses java.util.concurrent.ExecutorService, which
> allows to submit (execute) a Callable (instead of Runnable) task. This
> is very convenient for returning the exit code of the command line
> application to my Java code. It seems to me that this isn't possible
> with StandardThreadExecutor or any other executor that implement the
> |org.apache.catalina.Executor| interface?
> 
> Would it be appropriate to not use Tomcat's Executor and share my custom
> thread pool among all services by using Tomcat's common/shared class
> loader?

I think that would be better. On the other hand, you could create a
service that runs these things on your behalf, and then connect to that.
Then, you only have one thread pool in use, here. I think that will be
less fragile than trying to share a thread pool across web applications.
This also allows you to do thing like re-locate webapps that use the
pool without having to figure out what to do next: you just connect to
the same service you always did. It also makes it possible for you to
load-balance such a service if necessary without figuring out how to
change the clients of the service.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkuVF2QACgkQ9CaO5/Lv0PArSgCgwkGmosZtlnDJUWAGyJpeEX7L
QUsAoJZVO27SQITXqGQ/a193yY90650c
=wdN3
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [OT] Question on Executor (thread pool)

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: CBy [mailto:tomcat@byrman.demon.nl]
> Subject: Re: [OT] Question on Executor (thread pool)
> 
> I thought it was pretty common to share precious resources across web
> apps. Isn't database connection pooling often implemented this way?

Not in my experience - you want to keep things as separate as possible for ease of operation and maintenance.  You can use a single DB connection pool across webapps, but unless the webapps are fairly tightly coupled beyond using a common database, I wouldn't.

> If mine isn't, what then would be a good use case for using the shared
> class loader?

A few things come to mind:

1) Tomcat manages the resource of interest, so the classes have to be available to Tomcat code.

2) The webapps require a singleton (or equivalent static fields) on a global server basis.  (I would try to avoid this situation.)

3) A native library is being used, and since native code can only be loaded once per JVM, the Java classes have to be in shared.

The servlet spec is pretty clear about webapps being independent; coupling them ends up forcing administrators to take the server up and down rather than individual webapps.  It also makes upgrading one webapp at a time a difficult if not impossible task.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

Re: [OT] Question on Executor (thread pool)

Posted by CBy <to...@byrman.demon.nl>.
On 8-3-2010 17:07, Caldarale, Charles R wrote:
>> From: CBy [mailto:tomcat@byrman.demon.nl]
>> Subject: Re: [OT] Question on Executor (thread pool)
>>
>> I am still curious though on when and how to use Tomcat's Executor. I
>> someone could provide me with a nice example, I would be most grateful.
>>      
> Tomcat's thread pools used to be on a connector basis, so each had to be sized for the maximum load expected on the server.  Having a single executor shared by some connectors provides a more consistent way of tuning the server as a whole, while still allowing an individual thread pool for any connector that requires it.
>
> To second Chris' comment: sharing a thread pool between Tomcat and the dedicated needs of your webapp is just asking for trouble.  Don't try to force commonality on things that are unrelated, especially when it's so easy not to.
>    


Thanks for your advise, Chuck. To be honest, I am totally confused now.
I thought it was pretty common to share precious resources across web
apps. Isn't database connection pooling often implemented this way? If
mine isn't, what then would be a good use case for using the shared
class loader?

What is so easy about writing a dedicated service for this?



>   - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
>
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
>
>    


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [OT] Question on Executor (thread pool)

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: CBy [mailto:tomcat@byrman.demon.nl]
> Subject: Re: [OT] Question on Executor (thread pool)
> 
> I am still curious though on when and how to use Tomcat's Executor. I
> someone could provide me with a nice example, I would be most grateful.

Tomcat's thread pools used to be on a connector basis, so each had to be sized for the maximum load expected on the server.  Having a single executor shared by some connectors provides a more consistent way of tuning the server as a whole, while still allowing an individual thread pool for any connector that requires it.

To second Chris' comment: sharing a thread pool between Tomcat and the dedicated needs of your webapp is just asking for trouble.  Don't try to force commonality on things that are unrelated, especially when it's so easy not to.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

Re: [OT] Question on Executor (thread pool)

Posted by CBy <to...@byrman.demon.nl>.
Thanks for your help, Chris.

With "you could create a service" you mean a process not managed by 
Tomcat? The class loader route seems less flexible but easier. I think 
I'll try that first.

I am still curious though on when and how to use Tomcat's Executor. I 
someone could provide me with a nice example, I would be most grateful.

CBy

On 8-3-2010 16:27, Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> CBy,
>
> On 3/8/2010 7:03 AM, CBy wrote:
>    
>> My web service wraps a command-line application that is rather resource
>> demanding. To manage the maximum number of instances that can run
>> concurrently, it uses a (custom) thread pool.
>>      
> Are you on Java 1.5+?  (If not, you should be).
>
> If you are, you can use one of the fine implementations of executors in
> java.util.concurrent, such as ThreadPoolExecutor.
>
>    
>> Now that I have to
>> develop similar services, I would like to share the pool instead. I was
>> thinking of switching to Tomcat's Executor -
>> http://tomcat.apache.org/tomcat-6.0-doc/config/executor.html - but
>> cannot find any examples on how to use it.
>>      
> I don't believe user code has any access to Tomcat's thread pool(s). Why
> not run your own thread pool(s) for this particular requirement?
>
>    
>> If I uncomment the corresponding lines in server.xml, can I then use the
>> default tomcatThreadPool by just instantiating
>> org.apache.catalina.core.StandardThreadExecutor?
>>      
> Almost certainly not. You'd have to create your own
> StandardThreadExecutor, configure it, and then use it. The same is true
> if you were to use the Java API-provided one, except you wouldn't tie
> yourself to Tomcat in that case.
>
>    
>> Do I have to call start() and stop() on StandardThreadExecutor or is
>> this handled by Tomcat?
>>      
> If you used StandardThreadExecutor, Tomcat wouldn't be managing it: you
> would.
>
>    
>> Is it possible to block on the execute() method of StandardThreadExecutor?
>>
>> Can you only have one Executor per Connector?
>>
>> My current thread pool uses java.util.concurrent.ExecutorService, which
>> allows to submit (execute) a Callable (instead of Runnable) task. This
>> is very convenient for returning the exit code of the command line
>> application to my Java code. It seems to me that this isn't possible
>> with StandardThreadExecutor or any other executor that implement the
>> |org.apache.catalina.Executor| interface?
>>
>> Would it be appropriate to not use Tomcat's Executor and share my custom
>> thread pool among all services by using Tomcat's common/shared class
>> loader?
>>      
> I think that would be better. On the other hand, you could create a
> service that runs these things on your behalf, and then connect to that.
> Then, you only have one thread pool in use, here. I think that will be
> less fragile than trying to share a thread pool across web applications.
> This also allows you to do thing like re-locate webapps that use the
> pool without having to figure out what to do next: you just connect to
> the same service you always did. It also makes it possible for you to
> load-balance such a service if necessary without figuring out how to
> change the clients of the service.
>
> Hope that helps,
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkuVF2QACgkQ9CaO5/Lv0PArSgCgwkGmosZtlnDJUWAGyJpeEX7L
> QUsAoJZVO27SQITXqGQ/a193yY90650c
> =wdN3
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>    


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org