Hi!

Rick Horowitz wrote:
> If you have a moment, could you explain what the issue is. What is
> appropriate use of Thread.getContextClassLoader()?

Certainly. 

How would you typically do to get hold of a class whose name you know?
Class.forName() is probably the first to tome to mind, so you use that.
The problem is, which classloader is used? And the answer is: the same
that was used to load the class whose object did Class.forName(). This
is not a big problem if you're in a simple classloading environment
where there is basically only one classloader (the application loader),
but if you're in a more complex system, like jBoss, it won't work. Why?
Because, typically the library doing Class.forName() is loaded with the
system classloader (or similar, in our case it would be the server
classloader, which is a child to the system loader), which means that
Class.forName() would break since the class that it needs, which is part
of the component using the library for example, is not loaded through
that classloader. 

So, to fix this the library must be aware of the context in which it is
being used. The proper way to do this is to do all dynamic classloading
from the Thread.getContextClassLoader() classloader, since that is what
was used for the particular component that uses the library at that
particular point in time.

Is everything clear now, or do you want me to expand on something?

/Rickard

-- 
Rickard �berg

Email: [EMAIL PROTECTED]
http://www.telkel.com
http://www.jboss.org
http://www.dreambean.com



--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to