This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Threads and Synchronization and the fly likes Context Class Loader - very very confusing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Context Class Loader - very very confusing" Watch "Context Class Loader - very very confusing" New topic
Author

Context Class Loader - very very confusing

pooja jain
greenhorn
Ranch Hand

Joined: Jan 12, 2005
Posts: 213
could anyone please explain me getContextClassLoader() method and 'context class loader' in very simple way (if possible please give an example).

thanks.


:d
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

This article may help you.
First few paragraphs answers your question.
Additionally, this is what javadocs for the method says:
The context ClassLoader is provided by the creator of the thread for use by code running in this thread when loading classes and resources.

This can be different from the class loader of the current class(aka current classloader), a method of which is being executed.


apigee, a better way to API!
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
The Thread class provides the concept of a "context class loader". This is a ClassLoader associated with that Thread. Any thread started by that Thread will inherit the same context class loader. The initial main thread has the system class loader as its context class loader, but this can be changed via setContextClassLoader().

The context class loader will only be used to load classes if you specifically request it. By default, when JVM encounters a class that hasn't yet been loaded, it loads it with the ClassLoader that loaded the class that's currently running in that thread. To use the context class loader, you have to call loadClass() on the ClassLoader object returned by getContextClassLoader().

Any help?


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
 
wood burning stoves
 
subject: Context Class Loader - very very confusing