"Unable to get the context class loader for the current thread" in ExecutorService task

487 views
Skip to first unread message

Nikita Salnikov-Tarnovski

unread,
May 10, 2017, 8:38:40 AM5/10/17
to togglz-users
Hi.

I am trying to use Togglz 2.4.1.Final in Spring Boot application, but I have encountered the following error.

I submit a runnable to `java.util.concurrent.ExecutorService.submit` method. During runtime this runnable causes the following exception:

Caused by: java.lang.IllegalStateException: Unable to get the context class loader for the current thread!

       at org.togglz.core.context.FeatureContext.getContextClassLoader(FeatureContext.java:135)

       at org.togglz.core.context.FeatureContext.getFeatureManagerOrNull(FeatureContext.java:69)

       at org.togglz.core.context.FeatureContext.getFeatureManager(FeatureContext.java:47)

       at eu.plumbr.portal.integration.togglz.PlumbrFeatures.isActive(PlumbrFeatures.java:10)
....skipped...

       at java.util.concurrent.FutureTask.run(FutureTask.java:266)

       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)


where PlumbrFeature is as follows:

public enum PlumbrFeatures implements Feature {
 
HZ_LOOKUP;

 
public boolean isActive() {
   
return FeatureContext.getFeatureManager().isActive(this);
 
}

}

What am I doing wrong?

Nikita Salnikov-Tarnovski

unread,
May 10, 2017, 8:50:33 AM5/10/17
to togglz-users
Mnjah. It seems I have found the problem myself. This executor services uses a custom thread factory which manually sets context classloader to null for some reason...

Christian Kaltepoth

unread,
May 11, 2017, 3:52:12 AM5/11/17
to togglz...@googlegroups.com
Nice to hear you fixed your problem. Yes, a custom thread pool without a context classloader could cause these issues.
Reply all
Reply to author
Forward
0 new messages