使用前提:
1. thread中要进行while操作时。
2. 控制thread退出。
使用方法:
1. this.isInterrupted() 判断退出。接收到 mMyThread1.interrupt();则退出
private class MyThread1 extends Thread {
@Override
public void run() {
while (!this.isInterrupted()) {
// do our things
}
}
}
2. catch InterruptedException 退出, 同样接收到 mMyThread1.interrupt();则退出
private class MyThread2 extends Thread {
@Override
public void run() {
while (true) {
// do our things
try {
Thread.sleep(1000);
}catch (InterruptedException e) {
e.printStackTrace();
break;
}
}
}
}