使用前提:
thread中要进行while操作时。
需要控制thread退出。
使用方法:
this.isInterrupted() 判断退出。接收到 mMyThread1.interrupt();则退出。
private class MyThread1 extends Thread { @Override public void run() { while (!this.isInterrupted()) { // do our things } } }
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; } } } }
转载自:http://blog.csdn.net/wuyuxing24/article/details/45342049