我正在運(yùn)行一段代碼來(lái)理解守護(hù)進(jìn)程線程的概念和線程終止。即使在 main 方法完成后,程序仍會(huì)繼續(xù)打印。我在這里錯(cuò)過(guò)了什么嗎?package threading;public class ThreadInterruption { public static void main(String[] args) { Thread t = new Thread(new RanThread()); t.start(); t.setDaemon(true); t.interrupt(); }}class RanThread implements Runnable{ @Override public void run() { int count=0; while(true) { System.out.println("Ha Ha Ha "+ count); count=count+1; } }}提前致謝。
為什么 setdaemon 屬性在主線程結(jié)束時(shí)不結(jié)束子線程?
千萬(wàn)里不及你
2023-01-05 17:02:51