当前位置:网站首页>Daemon and user threads
Daemon and user threads
2022-06-30 06:58:00 【A Xiaoming】
1. Basic knowledge of :
Threads are divided into user threads and guard threads
The virtual machine must make sure that the user thread is finished ( That is, the execution of the user thread ends , Virtual machine will end )
The virtual machine doesn't have to wait for the daemons to finish executing ( That is, the daemon thread and the virtual machine exist or die together )
Common daemon threads such as , Record the operation log in the background , Monitor memory , Garbage collection waiting …
2. Example
/** Daemons and user threads */
public class TestDaemon {
public static void main(String[] args) {
God god = new God();
Person p = new Person();
Thread daemon = new Thread(god);
daemon.setDaemon(true); // Set to daemons , Live or die with the virtual machine , The default is false, That is, the user thread is assumed by default
daemon.start();
Thread common = new Thread(p);
common.start();
}
}
class God implements Runnable{
@Override
public void run() {
while (true) {
System.out.println(" God is watching over you ....");
}
}
}
class Person implements Runnable{
@Override
public void run() {
for (int i = 1;i<35000;i++){
System.out.println(" Live happily every day ....");
}
System.out.println("===========Goodbye world...");
}
}
Execution results :
The user thread and the daemon thread execute together 
End of user thread execution , Daemon thread continues execution 
Execute until the virtual machine stops .
边栏推荐
- RT thread Kernel Implementation (V): timer
- Pay attention to this live broadcast and learn about the path to achieve the dual carbon goal of the energy industry
- sscanf 函数的使用
- [JSON tutorial] Chapter 1 learning notes
- Vscode returns the previous cursor (previous browse position)
- Imxq Freescale yocto project compilation record
- 相关数据库问题提问。
- Huawei full-scale Daniel shared the 598 page full-color Manual of network protocols for the first time
- How to convert XML to JSON
- c# - C#用fo-dicom对CT图像的PixelData进行处理和转换
猜你喜欢

Pay attention to this live broadcast and learn about the path to achieve the dual carbon goal of the energy industry

Bat usage details 2

Basic questions (I)

Go常用命令

汇编语言学习一(有栈协程铺垫,32位寄存器和相关指令学习,未完待续06/29)

基础刷题(一)

Keil - the "trace HW not present" appears during download debugging

1.9 - Cache

Relevant database questions.

Go installation and configuration (1)
随机推荐
明天!“移动云杯”大赛空宣会开播!
原来你是这样的数组,终于学会了
【Mask-RCNN】基于Mask-RCNN的目标检测和识别
Joseph problem C language
Go语言指针介绍
Ffmplay is not generated during the compilation and installation of ffmpeg source code
sscanf 函数的使用
1.9 - Cache
图解八股,真的太顶了
1.6 - CPU composition
【Hot100】11. 盛最多水的容器
Basic fragmentary thoughts
Go项目目录结构介绍
Traverse map
六,购物⻋与订单
Goland常用快捷键设置
The 40g high-efficiency cloud disk purchased by Alibaba cloud is only 20g attached
RT thread application
MySQL中的InnoDB引擎
NFS mount