您的位置:首页 > 移动开发 > Android开发

android:Thread.interrupt()

2016-01-27 11:19 405 查看
使用前提:

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;
}
}
}
}


转载自:/article/8687479.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: