java 中断 继续_关于中断的线程如何继续。。在线等
該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓
看看這個例子
public class TestThread implements Runnable{
boolean stop = false;
public static void main(String[] args) throws Exception {
Thread thread = new Thread(new TestThread(),"My Thread");
System.out.println( "Starting thread..." );
thread.start();
Thread.sleep( 3000 );
System.out.println( "Interrupting thread..." );
thread.interrupt();
System.out.println("線程是否中斷:" + thread.isInterrupted());
Thread.sleep( 3000 );
System.out.println("Stopping application..." );
}
public void run() {
while(!stop){
System.out.println( "My Thread is running..." );
// 讓該循環(huán)持續(xù)一段時間,使上面的話打印次數(shù)少點(diǎn)
long time = System.currentTimeMillis();
while((System.currentTimeMillis()-time < 1000)) {
}
}
System.out.println("My Thread exiting under request..." );
}
}
總結(jié)
以上是生活随笔為你收集整理的java 中断 继续_关于中断的线程如何继续。。在线等的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 加载dll后打包_让Jacob
- 下一篇: java c 解决方案_Java jd