Skip to content

Commit 94634e8

Browse files
committed
fix: use classloader of jetcache as heavyIOExecutor thread context classloader
1 parent 64ceb19 commit 94634e8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

jetcache-core/src/main/java/com/alicp/jetcache/support/JetCacheExecutor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class JetCacheExecutor {
1717
protected volatile static ScheduledExecutorService heavyIOExecutor;
1818
private static final ReentrantLock reentrantLock = new ReentrantLock();
1919

20-
private static AtomicInteger threadCount = new AtomicInteger(0);
20+
private static final AtomicInteger threadCount = new AtomicInteger(0);
2121

2222
static {
2323
Runtime.getRuntime().addShutdownHook(new Thread() {
@@ -73,6 +73,13 @@ public static ScheduledExecutorService heavyIOExecutor() {
7373
ThreadFactory tf = r -> {
7474
Thread t = new Thread(r, "JetCacheHeavyIOExecutor" + threadCount.getAndIncrement());
7575
t.setDaemon(true);
76+
ClassLoader classLoader = JetCacheExecutor.class.getClassLoader();
77+
if (classLoader == null) {
78+
// This class was loaded by the Bootstrap ClassLoader,
79+
// so let's tie the thread's context ClassLoader to the System ClassLoader instead.
80+
classLoader = ClassLoader.getSystemClassLoader();
81+
}
82+
t.setContextClassLoader(classLoader);
7683
return t;
7784
};
7885
heavyIOExecutor = new ScheduledThreadPoolExecutor(

0 commit comments

Comments
 (0)