File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Context Class Loader - very very confusing

 
pooja jain
greenhorn
Ranch Hand
Posts: 213
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could anyone please explain me getContextClassLoader() method and 'context class loader' in very simple way (if possible please give an example).

thanks.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic