@ -223,12 +223,13 @@ public static void main(String[] args) {
|
|||||||
|
|
||||||
main() 属于非守护线程。
|
main() 属于非守护线程。
|
||||||
|
|
||||||
使用 setDaemon() 方法将一个线程设置为守护线程。
|
在线程启动之前使用 setDaemon() 方法可以将一个线程设置为守护线程。
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Thread thread = new Thread(new MyRunnable());
|
Thread thread = new Thread(new MyRunnable());
|
||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user