I\'m trying to stop a thread but I can\'t do that :
public class Middleware {
public void read() {
try {
socket = new Socket(\"192.168.1.8\", 20
if you want to interrupt a running thread, then you need to have access to the thread object.
thread = new Thread(scan);
thread.start();
then say
thread.interrupt();
this will interrupt the running thread.
Completely agree with Jim.. Just to add If your thread is blocked inside the try block for instance reading on a datastream etc then interrupt the thread as well or close the stream. In both cases the thread should be wakened up again and it will then be able to see the change in the value of "stop" boolean and die naturally by falling out of the run method. At least this is what I did to kill my threads in the shutdown thread for my server.