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
Simply return;
from your while and the thread will die, no need to call stop() or interrupt(). If you want to do it externally then use this pattern and call requestStop()
.
class Scan extends Thread {
private volatile stop = false;
public void run() {
while (!stop) {
try {
// my code goes here
} catch (IOException ex) {
stop = true;
}
}
}
public void requestStop() {
stop = true;
}
}