...
This noncompliant solution uses the advice suggested in the previous compliant solution. Unfortunately, this does not help in terminating the thread since it is blocked on some network IO due to the readLine
method. The boolean flag trick will thus as a result not work in such cases; a good alternative method to end the thread is required.
...
The compliant solution simply closes the socket connection, both using the shutdown
method as well as in the finally
block. ThusAs a result, the thread is bound to stop due to a socketException
. Note that there is no way to keep the connection alive if the thread is to be cleanly halted immediately.
...
Trying to force thread shutdown can lead to inconsistent object state and thus as a result corrupt the object. Critical resources may also leak if cleanup operations are not carried out as required.
...