Java 멀티스레드 이후 데스크톱 스레드가finally를 실행하지 않음
2260 단어 java 다중 루틴
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();
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
자바 기본 튜토리얼 양보 자바 다중 튜토리얼1. yield() 소개 yield()의 역할은 양보입니다.이것은 현재 스레드가'실행 상태'에서'준비 상태'로 들어가서 같은 우선순위를 가진 다른 대기 스레드가 실행권을 얻도록 할 수 있다.단, 현재 스레드가 yie...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.