소스 검색

try our best to do verbose output, but in a termination situation we may get a NoClassDefFoundError, if so, log it

tags/2.0.1
Jonathan Cobb 4 년 전
부모
커밋
678d760a0c
1개의 변경된 파일12개의 추가작업 그리고 4개의 파일을 삭제
  1. +12
    -4
      src/main/java/org/cobbzilla/util/daemon/ZillaRuntime.java

+ 12
- 4
src/main/java/org/cobbzilla/util/daemon/ZillaRuntime.java 파일 보기

@@ -79,7 +79,7 @@ public class ZillaRuntime {
public static TerminationRequestResult terminate(Thread thread, long timeout, Function<Thread, Boolean> onlyIf, boolean verbose) {
if (thread == null || !thread.isAlive()) return TerminationRequestResult.dead;
if (onlyIf != null && !onlyIf.apply(thread)) {
if (log.isWarnEnabled()) log.warn("terminate: thread is alive but onlyIf function returned false, not interrupting: " + thread + (verbose ? " with stack " + stacktrace(thread) + "\nfrom: " + stacktrace() : ""));
if (log.isWarnEnabled()) log.warn("terminate: thread is alive but onlyIf function returned false, not interrupting: " + thread + terminateVerbose(thread, verbose));
return TerminationRequestResult.alive;
}
thread.interrupt();
@@ -89,19 +89,27 @@ public class ZillaRuntime {
}
if (thread.isAlive()) {
if (onlyIf != null && onlyIf.apply(thread)) {
if (log.isWarnEnabled()) log.warn("terminate: thread did not respond to interrupt, killing: " + thread + (verbose ? " with stack " + stacktrace(thread) + "\nfrom: " + stacktrace() : ""));
if (log.isWarnEnabled()) log.warn("terminate: thread did not respond to interrupt, killing: " + thread + terminateVerbose(thread, verbose));
thread.stop();
return TerminationRequestResult.terminated;
} else {
if (log.isWarnEnabled()) log.warn("terminate: thread did not respond to interrupt, but onlyIf function returned false, not killing: " + thread + (verbose ? " with stack " + stacktrace(thread) + "\nfrom: " + stacktrace() : ""));
if (log.isWarnEnabled()) log.warn("terminate: thread did not respond to interrupt, but onlyIf function returned false, not killing: " + thread + terminateVerbose(thread, verbose));
return TerminationRequestResult.interrupted_alive;
}
} else {
if (log.isWarnEnabled()) log.warn("terminate: thread exited after interrupt: "+thread+(thread.getName().startsWith("Thread-") ? " with stack: "+stacktrace(thread) : ""));
if (log.isWarnEnabled()) log.warn("terminate: thread exited after interrupt: "+thread + terminateVerbose(thread, verbose));
return TerminationRequestResult.interrupted_dead;
}
}

public static String terminateVerbose(Thread thread, boolean verbose) {
try {
return verbose || thread.getName().startsWith("Thread-") ? " with stack " + stacktrace(thread) + "\nfrom: " + stacktrace() : "";
} catch (NoClassDefFoundError e) {
return "(verbose output error: NoClassDefFoundError: "+e.getMessage()+")";
}
}

public static String threadName() { return Thread.currentThread().getName(); }

public static boolean bool(Boolean b) { return b != null && b; }


불러오는 중...
취소
저장