fix false positive on ungraceful shutdown warning

This commit is contained in:
Jonathan Shook 2023-09-10 19:17:47 -05:00
parent 7b9f4389b8
commit 0668d1db0c
2 changed files with 10 additions and 6 deletions

View File

@ -421,7 +421,7 @@ public class ActivityExecutor implements NBLabeledElement, ActivityController, P
activity.shutdownActivity(); activity.shutdownActivity();
activity.closeAutoCloseables(); activity.closeAutoCloseables();
ExecutionResult result = new ExecutionResult(startedAt, stoppedAt, "", exception); ExecutionResult result = new ExecutionResult(startedAt, stoppedAt, "", exception);
finish(); finish(true);
return result; return result;
} }
} }
@ -548,11 +548,15 @@ public class ActivityExecutor implements NBLabeledElement, ActivityController, P
return activity.getLabels(); return activity.getLabels();
} }
public synchronized void finish() { public synchronized void finish(boolean graceful) {
if (shutdownHook!=null) { if (graceful) {
logger.warn("Activity was interrupted by process exit, shutting down"); Runtime.getRuntime().removeShutdownHook(shutdownHook);
} else {
logger.warn("Activity was interrupted by process exit, shutting down ungracefully. Annotations are still submitted.");
} }
shutdownHook=null; if (shutdownHook==null) return; // In case of a race condition, only prevented by object monitor
else shutdownHook=null;
stoppedAt = System.currentTimeMillis(); //TODO: Make only one endedAtMillis assignment stoppedAt = System.currentTimeMillis(); //TODO: Make only one endedAtMillis assignment
Annotators.recordAnnotation(Annotation.newBuilder() Annotators.recordAnnotation(Annotation.newBuilder()

View File

@ -25,7 +25,7 @@ public class ActivityExecutorShutdownHook extends Thread {
@Override @Override
public void run() { public void run() {
activityExecutor.finish(); activityExecutor.finish(false);
} }
} }