classloader
David Holmes - Sun Microsystems
David.Holmes at Sun.COM
Fri Oct 9 01:00:53 PDT 2009
Hi Eric,
Eric J. Van der Velden said the following on 10/09/09 15:02:
> Suppose X is a class type, and a class loader is created,
>
> ClassLoader l=...
> Thread.currentThread().setContextClassLoader(l)
> Object o=new X()
>
> Why is X not loaded by l, but still by the application class loader?
This is off-topic for this hotspot-dev mailing and would be better asked
in one of the Java programming forums. But the simple answer is because
the application class loader remains the current classloader for the
current thread within the code that does "new X()".
The context classloader is typically used by code that executes under
the boot loader or extensions loader and which needs to load a type that
can only be found by a classloader lower in the hierarchy - hence they
will query for it and then use it to load a class by name eg:
Class xClass =
Thread.currentThread().getContextClassLoader().loadClass("X");
Hope this helps, but please don't post follow ups on the mailing list.
David Holmes
More information about the hotspot-dev
mailing list