in graalvm-native-image-demo/opentelemetry-agent-native/src/main/java/com/alibaba/jvm/ExecutorsAspect.java [205:233]
public static void submitExit(Collection<? extends Callable<?>> originalTasks,
@Advice.BeforeResult Collection<? extends Callable<?>> tasks,
@Advice.Thrown Throwable throwable) {
try {
/*
* Note1: invokeAny doesn't return any futures so all we need to do for it
* is to make sure we close all scopes in case of an exception.
* Note2: invokeAll does return futures - but according to its documentation
* it actually only returns after all futures have been completed - i.e. it
* blocks.
* This means we do not need to setup any hooks on these futures, we just need
* to clear
* any parent spans in case of an error.
* (according to ExecutorService docs and AbstractExecutorService code)
*/
if (throwable != null) {
for (Callable<?> task : tasks) {
if (task != null) {
VirtualField<Callable<?>, PropagatedContext> virtualField = VirtualField.find(Callable.class,
PropagatedContext.class);
PropagatedContext propagatedContext = virtualField.get(task);
ExecutorAdviceHelper.cleanUpAfterSubmit(propagatedContext, throwable);
}
}
}
} catch (Throwable t) {
}
}