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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



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

Reply via email to