I have a
thread which is started when its outer class is instantiated. At any given time, this thread likely to be blocked by a DatagramSocket.read() call, and it is in an infinite loop. I want to write a method called close() which, among other things, will kill this thread. My first thought was for the loop condition to be an instance variable which could be modified. Naturally, this cannot be the case as if the thread has been blocked, it may never get back to
test this variable (and subsequently break the loop).
Is there a way to cause a thread to stop what its doing and go into a cleanup routine?