mirror of
https://github.com/CyC2018/CS-Notes.git
synced 2025-07-05 16:17:45 +08:00
@ -223,12 +223,13 @@ public static void main(String[] args) {
|
||||
|
||||
main() 属于非守护线程。
|
||||
|
||||
使用 setDaemon() 方法将一个线程设置为守护线程。
|
||||
在线程启动之前使用 setDaemon() 方法可以将一个线程设置为守护线程。
|
||||
|
||||
```java
|
||||
public static void main(String[] args) {
|
||||
Thread thread = new Thread(new MyRunnable());
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
}
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user