当前位置:网站首页>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 .
边栏推荐
- Porting RT thread to s5p4418 (V): thread communication
- 【docsify基本使用】
- RT thread Kernel Implementation (I): threads and scheduling
- C language: exercise 3
- 1.6 - CPU composition
- ROS program compilation, like no compilation, refers to the execution of the old compiled executable program
- 汇编语言学习一(有栈协程铺垫,32位寄存器和相关指令学习,未完待续06/29)
- 六,购物⻋与订单
- Xshell transfer file
- Go项目目录结构介绍
猜你喜欢
Graphic octet, really top
【Mask-RCNN】基于Mask-RCNN的目标检测和识别
Porting RT thread to s5p4418 (V): thread communication
SOC项目AHB_SD_HOST控制器设计
第一行代码(第三版)学习笔记
Google Earth engine (GEE) - Murray global tidal wetland change V1 (1999-2019) data set
经纬恒润再次荣获PACCAR集团 10PPM 质量奖
1285_把AUTOSAR函数以及变量等定义的宏用脚本展开以提高可读性
【我的OpenGL学习进阶之旅】关于OpenGL的着色器的向量和矩阵分类的访问方式: xyzw/rgba/stpq以及数组下标
leetcode:98. Validate binary search tree
随机推荐
阿里云买的40G高效云盘挂载只有20G
0基础转行软件测试,如何实现月薪9.5k+
Imxq Freescale yocto project compilation record
Goland常用快捷键设置
Force buckle ------ replace blank space
Go项目目录结构介绍
1.3 - Code System
The solution of memcpy memory overlap
[Hot100]10. Regular Expression Matching
SOC project AHB_ SD_ Host controller design
Write a C program to judge whether the system is large end byte order or small end byte order
Bat usage details 2
Steps for formulating class or file templates in idea
How to set the hot deployment of idea web project
ROS system problem: rosdep init
sscanf 函数的使用
[JSON tutorial] Chapter 1 learning notes
经纬恒润再次荣获PACCAR集团 10PPM 质量奖
First line of code (Third Edition) learning notes
It turns out that you are such an array. You have finally learned