0
点赞
收藏
分享

微信扫一扫

AOP(面向切面编程)基于XML方式配置

茗越 2024-01-07 阅读 5
junitjava

Junit单元测试主线程退出,子线程也会退出

    @Test
    public void test() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName()+":finish");
        }, "t1");
        t1.start(); 
    }

可以看到什么都不会打印,如果给主线程也加上sleep,那就可以了

    @Test
    public void test() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName()+":finish");
        }, "t1");
        t1.start();
        TimeUnit.SECONDS.sleep(6);
    }

举报

相关推荐

0 条评论