public class DaemonThreadDemo { public static void main(String[] args) { Thread mainThread = new Thread(()->{ Thread childThread = new Thread(new DaemonThread()); childThread.setDaemon(true); childThread.start(); System.out.println("我是主线程!!!"); }); mainThread.start(); } } class DaemonThread implements Runnable { @Override public void run() { while(true) { try { Thread.currentThread().sleep(1000); System.out.println("我是守护线程!!!"); } catch (InterruptedException e) { e.printStackTrace(); } } } }
守护线程简单的DEMO!!!
最新推荐文章于 2024-05-10 19:39:30 发布