keith-turner commented on code in PR #50:
URL:
https://github.com/apache/accumulo-classloaders/pull/50#discussion_r2709370389
##########
modules/local-caching-classloader/src/main/java/org/apache/accumulo/classloader/lcc/LocalCachingContextClassLoaderFactory.java:
##########
@@ -99,7 +117,12 @@ public class LocalCachingContextClassLoaderFactory
implements ContextClassLoader
private static final Logger LOG =
LoggerFactory.getLogger(LocalCachingContextClassLoaderFactory.class);
- private final ScheduledExecutorService EXECUTOR =
Executors.newScheduledThreadPool(0);
+ private final ScheduledThreadPoolExecutor executor =
+ new ScheduledThreadPoolExecutor(1, new
ContextClassLoaderThreadFactory());
Review Comment:
Not sure the uncaught exception handler for the threads created in the
factory will ever be called. Looking at ScheduledThreadPoolExecutor it always
creates futures internally (even when calling `void execute(Runnable)`) and
these futures will always catch all exceptions.
The following is a program I created trying to understand this, it does not
work (never prints an exception) and was a dead end but maybe its helpful.
After I created this I found `ScheduledThreadPoolExecutor.decorateTask()`,
maybe that is a way to solve this but not sure.
```java
public class Test {
public static void main(String[] args) {
ThreadFactory tf = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
Thread.UncaughtExceptionHandler ue = (t1, e) -> {
System.out.println("HERE");
if(e != null) {
e.printStackTrace();
}
};
t.setUncaughtExceptionHandler(ue);
return t;
}
};
ScheduledThreadPoolExecutor spe = new ScheduledThreadPoolExecutor(1,
tf){
@Override
protected void afterExecute(Runnable r, Throwable t) {
// found this is a dead end, this is never called by
ScheduledThreadPoolExecutor... the javadoc for ScheduledThreadPoolExecutor
mentions this
super.afterExecute(r, t);
System.out.println("HERE 3 "+t);
if( t != null) {
t.printStackTrace();
}
}
};
spe.execute(()->{
System.out.println("HERE 4");
throw new Error("test");
});
spe.execute(()->{
System.out.println("HERE 5");
throw new IllegalStateException();
});
spe.schedule(()->{
System.out.println("HERE 6");
throw new IllegalStateException();
}, 1, TimeUnit.MILLISECONDS);
System.out.println("HERE 2");
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]