Lee Francis Wilhelmsen wrote:
> Does this look ok? I'm having trouble getting the Worker.doWork() algorithm
> to terminiate it's operation? I'm thinking fairly general here. The
> algorithm contains a loop. Should each iteration check Thread.interrupted()
> and break if true? Should it throw an InterruptedException? Both (depending
> the thread state)
What you've posted looks fine -- but the important part is how you're
handling the interrupt, and that you didn't bother to post.
Note that setting the Thread to null doesn't particularily help to kill
off the thread. A ThreadGroup object will still hold a reference to the
thread so long as it's alive, so setting it to null in your MyClass
isn't going to cause it to be marked for garbage collection
automatically (it's still not a bad idea to do -- it just doesn't help
kill the thread).
If your loop is running a lengthy operation, then yes -- it should
regularily check to see wether or not it's been interrupted. Otherwise
it will continue to run. Depending on wether or not any cleanup is
necessary, you can either break out of the loop (ensuring that by doing
so you're not going to fall into another loop...), or simply return
(which causes an immediate end to the thread).
HTH!
Brad BARCLAY
--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project:
http://www.jsyncmanager.org