浅析java线程中断的办法(2)

package com.xiaojiezhu.thread; /** * @author xiaojie.zhu */ public class ThreadBreak4 implements Runnable { @Override public void run() { System.out.println("进入线程"); try { Thread.sleep(20000); System.out.println("结束线程"); } catch (InterruptedException e) { e.printStackTrace(); } } public static void main(String[] args) { Thread t = new Thread(new ThreadBreak4()); t.start(); try { Thread.sleep(200); t.stop(); System.out.println("over"); } catch (InterruptedException e) { e.printStackTrace(); } } }

打印结果如下

进入线程
over

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/076df510526cce6d3e95216c7cac911c.html