tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: Need to create a new thread for async operations
Date Mon, 10 Jan 2011 20:28:02 GMT
Hash: SHA1


On 1/9/2011 11:27 AM, Captain Cid wrote:
> I am having a CXF webservice impl class. In this I want to start a new thread
> in service impl constructor. This is because I need to run a thread will
> continuously do some operation in background using database. And I need to
> be able to stop it when tomcat is shutdown.

If you only need a single thread to run all the time go ahead and create
it in a ServletContextListener (or via a Spring-manager object if you
want). Just remember to stop the thread, later.

> I was searching net. Found that it can be done using executor etc. But still
> I am unable to find it. Any help appreciated.

If you need to run more than one thread, I highly recommend using an
executor: you can submit a job to a ThreadPoolExecutor and it will be
run when there is a free thread. This helps limit your resource usage
even under load: that is, you won't be firing off hundreds of threads if
you get swamped by requests that need to schedule background jobs.
Instead, your job queue simply grows longer.

- -chris
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message