I have the following code:
renderThread = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 10000000; i++) {
System.out.println("Number: " + i);
}
}
});
renderThread.start();
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
renderThread.interrupt(); //It should stop, but it does not stop.
renderThread.interrupt() does not interrupt the thread, it continues to run. If I replace renderThread.interrupt() with .stop(), then the thread stops. However, .stop() is deprecated.
Then, what is the proper way of stopping a thread, if stop is deprecated and interrupt does not work?