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

David,

On 5/1/2009 1:23 PM, David.Meldrum wrote:
> Chris, This is a good point.  What I am discovering is that while I was
> calling a terminate method on the Thread in the
> ContextListener.contextDestroyed() method, my thread lives for quite
> while, because it is sleeping and does not wake up to test the terminate
> flag for several minutes.  My solution was to reduce the sleep time down
> to a few seconds and only really do something every 20 time it wakes
> up.

How does it sleep? Thread.sleep()? What does this thread do? Could you
use synchronized(foo) { foo.wait(); } and foo.notify() instead of
polling? If so, you could send a notify to the lock monitor and wake up
the thread immediately. You could also call yourThread.interrupt, which
should interrupt a Thread.sleep() call.

> This allowed it to discover the terminate flag much sooner.  I did
> not call the "destroy()" method because I though it was deprecated and
> dangerous.

It is. If your thread has a "please die" boolean that it checks, you
should simply set that and allow the thread to finish on its own.

> I noticed that the Probe  application does have a destroy
> Thread  which works, but warns of being dangerous.

I think the problem is with synchronization locks: when you murder a
thread, it doesn't give up its locks which can be a BIG problem. I
suspect your threads hold few (or any) locks so it's probably okay to do
from a profiler or whatever, but it's best to be avoided in your code.

> I am still trying to figure out why a second thread is spawned. Haven't
> gotten to bottom of that issue yet.

You never told us what the stack trace in init() shows. (!)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkn/TWUACgkQ9CaO5/Lv0PB1nQCgtNogXU+FxWs8EzX71ogJfHov
7jcAn2TPgoLuerPGUh2LhY+1Vz4D1rXs
=lSpl
-----END PGP SIGNATURE-----

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

Reply via email to