栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

关于spring(?)的问题

关于spring(?)的问题

Test的原因吗?还是Tomcat的原因?

1.单元测试
 @Test
 public void test(){
        System.out.println(Thread.currentThread().getName());
        new Thread(() -> {
            {
                try {
                    System.out.println(Thread.currentThread().getName());
                    Thread.currentThread().sleep(1000);
                    System.out.println(Thread.currentThread().getName() + "over");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }).start();
        System.out.println(Thread.currentThread().getName() + ":over");
    }

结果:

main
main:over
Thread-0

2.SpringBootTest
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class SpringbootRedisApplicationTests {
    @Test
    void test() throws InterruptedException {
        System.out.println(Thread.currentThread().getName());
        new Thread(() -> {
            {
                try {
                    for (int i = 0; i < 10; i++) {
                        System.out.println(Thread.currentThread().getName());
                        Thread.currentThread().sleep(1000);
                        System.out.println(Thread.currentThread().getName() + "over");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }).start();
        System.out.println(Thread.currentThread().getName() + ":over");
    }

结果:

main
main:over
Thread-3

3.普通Java项目
    public static void main(String[] args) throws Exception {
        System.out.println(Thread.currentThread().getName());
        new Thread(() -> {
            {
                try {
                        System.out.println(Thread.currentThread().getName());
                        Thread.currentThread().sleep(1000);
                        System.out.println(Thread.currentThread().getName() + "over");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }).start();
        System.out.println(Thread.currentThread().getName() + ":over");
    }

结果:

main
main:over
Thread-0
Thread-0over

4.Springboot项目
@SpringBootApplication
public class SpringbootRedisApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SpringbootRedisApplication.class, args);
        System.out.println(Thread.currentThread().getName());
        new Thread(() -> {
            {
                try {
                    System.out.println(Thread.currentThread().getName());
                    Thread.currentThread().sleep(1000);
                    System.out.println(Thread.currentThread().getName() + "over");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }).start();
        System.out.println(Thread.currentThread().getName() + ":over");
    }

}

结果:

restartedMain
restartedMain:over
Thread-9
Thread-9over

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/711767.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号