Java 멀티스레드 이후 데스크톱 스레드가finally를 실행하지 않음

2260 단어 java 다중 루틴
백엔드 스레드가finally를 실행하지 않습니다
package wzh.daemon;

import java.util.concurrent.TimeUnit;

class ADaemon implements Runnable {

    @Override
    public void run() {
        try {
            System.out.println("Starting ADaemon");
            TimeUnit.SECONDS.sleep(1);
        } catch (Exception e) {
            System.out.println("Exiting via InterruptedException");
        } finally {
            //       , finally     。
            //        ,          。
            System.out.println("This should always run?");
        }
    }

}

public class DaemonsDontRunFinally {
    public static void main(String[] args) {
        Thread thread = new Thread(new ADaemon());
        thread.setDaemon(true);
        thread.start();
    }
}

좋은 웹페이지 즐겨찾기