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.closeAutoCloseables();
ExecutionResult result = new ExecutionResult(startedAt, stoppedAt, "", exception);
finish();
finish(true);
return result;
}
}
@ -548,11 +548,15 @@ public class ActivityExecutor implements NBLabeledElement, ActivityController, P
return activity.getLabels();
}
public synchronized void finish() {
if (shutdownHook!=null) {
logger.warn("Activity was interrupted by process exit, shutting down");
public synchronized void finish(boolean graceful) {
if (graceful) {
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
Annotators.recordAnnotation(Annotation.newBuilder()

View File

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