The thread is working until it is interrupted but it is sleeping from time to time:
public void run() {
while (!Thread.interrupted()) {
//A TASK HERE
try {
Thread.sleep((long) (500 + Math.random() * 100));
} catch (InterruptedException e) {
interrupt(); //it was interrupted while it was sleeping
}
}
}
The intention is to kill the thread by interrupting it. Can I reinterrupt itself like I did or I should set a flag stop = true within the exception clause?