代码如下:
@SpringBootApplication
@Controller
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
Thread thread = new Thread(() -> {
});
System.out.println("Thead 1 - > " + thread.isDaemon());
}
@GetMapping("/")
public void test() {
Thread thread = new Thread(() -> {
});
System.out.println("Thead 2 - > " + thread.isDaemon());
}
}
运行结果如图:
如上图所示,Java中创建线程默认都是用户线程。但是为什么在GetMapping中创建的线程却是守护线程?