Java守护线程和用户线程;多线程

37 阅读1分钟

@Test public void testT() { System.out.println("testT start"); Thread thread = new MyThread(); thread.setName("守护线程"); thread.setDaemon(true); thread.start(); System.out.println("testT end"); } class MyThread extends Thread { @Override public void run() { System.out.println(Thread.currentThread().getName()); System.out.println(Thread.currentThread().getId()); System.out.println("start"); try { Thread.sleep(1000); } catch (InterruptedException e) { log.error("e:", e); } System.out.println("end"); } }

本文使用 文章同步助手 同步