Wednesday, 21 August 2013

Why do subsequent jni threads return null on currentThread().getClassLoader()?

Why do subsequent jni threads return null on
currentThread().getClassLoader()?

I'm starting threads from c++ and calling into Java. The JVM itself has
the classpath set correctly with all the necessary jars passed to
-Djava.class.path.
Why would the "context class loader" ever be null in new threads?
I have this szenario:
ClassLoader cl = Thread.currentThread().getContextClassLoader(); // null
on new threads
ClassLoader currCl = MyClass.class.getClassLoader();
ClassLoader jbossCl =
org.jboss.remoting.InvocationResponse.class.getClassLoader();
In the first thread (it says "main" in Eclipse), all three objects are
valid and contain classes. In all following threads cl is null.
Doesn't make any sense to me, if I load classes into the JVM, they should
be available to every thread globally, shouldn't they? There's also a
wildly different amount of classes in currCl and jbossCl for some reason.
First has ~600 and the other one has >1000

No comments:

Post a Comment