<>JAVA Multithreading —— Daemons

Threads are divided into user threads ( as main thread ) And Daemons

The virtual machine must ensure that the user thread execution is complete

Virtual machines don't have to wait for the daemons to finish

The role of Daemons : Background record operation , journal , Monitor memory , garbage collection , Waiting mechanism, etc
package com.peng.demon04; // Test Daemons public class TestDaemon { public static void
main(String[] args) { Gad gad = new Gad(); You you = new You(); // Set as a daemon
Thread thread= new Thread(gad);// agent thread.setDaemon(true);// The default is false Represents a user thread
thread.start(); new Thread(you).start(); } } // lord Daemons class Gad implements
Runnable{ @Override public void run() { while (true){ System.out.println(" God is always there "
); } } } // you User thread As long as the user thread ends , The virtual machine stops , But it will take time to stop , So we'll run the daemons for a while class You implements
Runnable{ @Override public void run() { for (int i = 0; i < 30000; i++) { System
.out.println(" Live happily "); } System.out.println("goodbey world"); } }

©2019-2020 Toolsou All rights reserved,
Huawei 2021 session Hardware Engineer Logical post (FPGA) Super detailed surface !!!Vue-element-admin upgrade ui edition virtual machine VMware Download and install the most detailed tutorial !C++ Move constructor and copy constructor sound of dripping water java Backstage interview pygame Realize full screen mode and adjustable window size mysql Database setting character set configuration modification my.ini file (windows)30 What's the experience of being a junior programmer at the age of 20 C++ Multithreading programming ( Summary of common functions and parameters )python_ cherry tree