I m using windows 7 OS. I have around 6
threads in my application. For the purpose of testing the alerts to check the health of the threads, i need to kill the thre
As Peter says, you can't do this safely. Indeed on some platforms Thread.kill
is not even implemented. However:
If this is just for testing, a unit test that called Thread.kill
would be reasonable ... assuming it worked on the test platforms where it needed to work. (A "loud" comment in the source code would be in order to help people porting the unit test ...)
Another alternative is to add some code to the thread runnable that allows your unit tests to tell it to die. If the thread code needs to be (almost) production code for this to work, you could create a subclass that overrides something so that it "breaks" in a way that suits your purposes ... for testing. In fact, this approach allows you to cause the threads "break" in controlled ways, potentially allowing you to test different aspects of your alerting code.