So I create a thread
Thread personThread = new Thread(Person);
personThread.start();
/** Now to stop it **/
personThread.stop();
The problem is, when I try to compile I get: warning: [deprecation] stop() in Thread has been deprecated. As I am to understand, this is no longer used method. How can I then completely stop a thread, irrelevant of it's status?
解决方案
You should interrupt a thread, which is a gentle way of asking it to stop.
Shameless copy of myself:
final Thread thread = new Thread(someRunnable);
thread.start();
Instead of stop() call interrupt():
thread.interrupt();
And handle the interruption manually in the thread:
while(!Thread.currentThread().isInterrupted()){
try{
Thread.sleep(10);
}
catch(InterruptedException e){
Thread.currentThread().interrupt();
}