唤醒线程睡眠为什么会这样输出呐?

问题描述:

输出之后是:

t--->end不是应该在异常之后输出吗?

试了一下,没有重现你的效果。可以把代码直接贴出来帮你看看

public class ThreadTest03 {
    public static void main(String[] args) {
        Thread thread = new Thread(new MyThread2());
        //希望5秒之后t线程醒来
        thread.setName("t");
        thread.start();
        try {
            Thread.sleep(1000*5);
            System.out.println("jjj");
        } catch (InterruptedException e) {
            e.printStackTrace(); }
        //终止正在睡眠的线程
        thread.interrupt(); }}
class MyThread2 implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"--->begin");
        try {
            Thread.sleep(1000*60*60*24*365); } catch (InterruptedException e) {
            e.printStackTrace(); }
        System.out.println(Thread.currentThread().getName()+"--->end");
    }
}