我创建一个Thread,类似于下面的代码。这个Thread将发送POST request。(代码还没有编写,所以我没有发布Thread的详细代码)
final Runnable Update_Value = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
**// It will send the POST request to the Server**
}
};我使用new Thread(Update_Value).start();运行线程。
我使用new Thread(Update_Value).interrupt();中断线程。
如果我使用new Thread(Update_Value).start(); 来运行 Thread**.**,那么1.
如何在使用new Thread(Update_Value).start(); 时中断线程
3是应用程序关闭时的线程关闭,如果我不关闭它?
抱歉,我的English...Thanks提前了。
发布于 2014-10-02 06:55:12
new线程,那么这两个调用会创建两个不同的线程;它们不会在同一个线程上运行。interrupt()方法不会停止线程。相反,它告诉线程查看可能已经设置的任何中断标志,例如关闭标志。线程本身必须包含检查中断和检查标志(如关机标志)的代码。发布于 2014-10-02 06:59:27
interrupt方法用于向正在运行的线程发送中断信号。调用一个新线程是没有意义的。
要正确处理中断信号,线程代码应该捕获InterruptedException。就像这样:
try {
// do thread task
} catch (InterruptedException e) {
// interrupted: if required do something on interrupt or simply return
return;
}https://stackoverflow.com/questions/26155701
复制相似问题