tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Need to create a new thread for async operations
Date Mon, 10 Jan 2011 20:28:02 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Cid,

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0ra9IACgkQ9CaO5/Lv0PDa4QCeMI3XSO399vP6Hsc040KuB3oo
pFgAoKzVj3Rb1R4bdiiX/NzbABsWWwca
=AFKb
-----END PGP SIGNATURE-----

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


Mime
View raw message