powered by Jive Software

ContextClassLoader PluginClassLoader AccessControlException

I have a plugin that uses an ExecutorService to spawn new threads that do some dynamic class loading.

I learned that PluginClassLoader is used to initially load all my plugin classes (naturally). However, the context ClassLoader of the threads spawned by the ExecutorService is some AppClassLoader, which fails when trying to load my plugin’'s classes.

I tried setting the context ClassLoader of the new threads to be the PluginClassLoader, but I get “java.security.AccessControlException: access denied (java.lang.RuntimePermission setContextClassLoader)”.

Any advice?

Okay, it appears the threads created by ExecutorService have different ClassLoaders. Some have PluginClassLoader, some have AppClassLoader. Its a CachedThreadPool, and I suspect that one thread is created when the ExecutorService is constructed, and that it has the PluginClassLoader, and that the threads created thereafter have the AppClassLoader.

Also, I was passing in Executors.privilegedThreadFactory() to Executors.newCachedThreadPool() to set the context ClassLoader, which resulted in the permission problem I described above. However, manually setting the context ClassLoader in the Thread.run seems to work.

So, this seems to have been an ExecutorService problem, not a Spark one.