I have a question regarding threading in Java. In my code,
...
client.doSth();
// now need to get hold of the thread that is initiated by 'client'
(get a reference to the 'client' thread)
// now kills it
(kills the 'client' thread)
...
So what I would like to know is: in the first brackets, how do I programmatically get hold of a reference to the ‘client’ thread (NOT the main thread the program is running on), and in the second brackets, how do I properly kill it, i.e. without using the depreciated stop() method.
Many thanks.
Edit:
after rereading the question I am not sure any more if you have access to the client code. If you do, well you can revise it and not even use thread but
java.util.concurrent.ExecutorServiceor the likes.. yetSince the code is not your own… you are on your own to stop it.
ThreadGroup class is designed for. Managing partial programs or modules is not exactly easy and usually it takes some already established framework. Ensuring some 3rd party code will behave and be nice and all it’s not always possible. It should include context classloader and what not but here is a skimmed version of how it’s done.
Still there might be something you can do to break the bone of the intruder. Assuming stop()/close(), etc has been used, some tricks like ThreadDeath during logging and so on.
Good luck!