Re: starting threads from servlets
- From: Lee Ryman <leeryman@xxxxxxxxxxx>
- Date: Fri, 29 Apr 2005 22:56:32 +1000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
It is technically possible to create and start another thread from a
servlet, but IMHO it would be a very bad idea. Once the servlet returned
there would be little means to safely track the existence and state of
the created threads.
One cleaner and nicer means of having the app-server manage a thread for
the life of the web-app is to use a implementation of a
javax.servlet.ServletContextListener
which is initialised on deployment of your web-app using a couple of
lines in your web.xml file such as...
<listener>
<listener-class>ThreadManagerContextListener</listener-class>
</listener>
This listener could create some sort of singleton which controls your
database update thread, and servlets could query the singleton for
information. I haven't really spent alot of time thinking about applying
such a scheme to management of a separate thread, but I have used such a
system involving a context listener to manage a custom-made database
connection pool, and it worked quite well.
Its a basic idea. Any further information can be determined from the API
documents, Google, Java tutorials, etc.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iEYEARECAAYFAkJyLwAACgkQhbcFpQga0LA9jwCeInhUvRid3udm2EVjGnhYwDeq
IVgAoJA14wwBYaElTy36Sl6dX0u6Emwx
=cs4u
-----END PGP SIGNATURE-----
.
- Follow-Ups:
- Re: starting threads from servlets
- From: Lee Ryman
- Re: starting threads from servlets
- References:
- starting threads from servlets
- From: Fernando
- starting threads from servlets
- Prev by Date: Re: blocking calls in java
- Next by Date: Re: blocking calls in java
- Previous by thread: starting threads from servlets
- Next by thread: Re: starting threads from servlets
- Index(es):
Relevant Pages
|