1.守護執行緒(後台執行緒):
setdaemon(boolean b) 設定是否為守護執行緒
isdaemon() 返回是否為守護執行緒(是true否false)
注意:當程式停止執行的時候,守護執行緒也必須停止
publicclass demo11 implements
runnable
}public
static
void
main(string args)
}}
2.join 加入:
當在乙個執行緒任務體(run)中使用此方法時,必須要等呼叫join方法的執行緒執行完成任務後,這個任務體才能繼續執行
**例項:
class thread2 implementsrunnable
}}public
class demo12 implements
runnable catch
(interruptedexception e)
}system.out.println(thread.currentthread().getname()+":"+i);}}
public
static
void
main(string args)
}
python 守護程序執行緒,join
1.程序 守護程序隨著主程序的 結束而結束,注意是 主程序可能在等待其他的子程序 from multiprocessing import process def func while true time.sleep 0.2 print ok if name main p process target...
守護執行緒和執行緒常用方法
from threading import thread import time deftask print 子執行緒 開始工作 time.sleep 2 print 子執行緒 結束工作 t1 thread target task t1.daemon true t1.start print 主線程 ...
守護執行緒和非守護執行緒
基本概念 示例 非守護執行緒 public class mythread extends thread catch interruptedexception e system.out.println 執行緒 thread.currentthread getname 執行了 i 次 public st...