• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Context Class Loader - very very confusing

 
greenhorn
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic