Hi, can anyone tell me the differnece between thread.currentThread().getContextClassloader().loadClass("<class-name>") and class.forname("<class-name>")?
I am really confused between this two. I went through the javadoc also. I am also not aware of what does thread.currentthread.contextClassLoader() will return? Doen't the contextclassloader and class's classLoader are same?
Chop your own wood, and it will warm you twice. - Henry Ford
Originally posted by Kartik Patel: Doen't the contextclassloader and class's classLoader are same?
No, certainly not.
The current class's ClassLoader is whatever loaded that class and is fixed.
The thread context ClassLoader is under your control; you can set it. If you haven't set it yourself, it defaults to the thread context ClassLoader of the thread that started the current thread. If the current thread is the main thread, the default context ClassLoader is the system ClassLoader (the one that works with the classpath).
In applications with multiple ClassLoaders, I tend to find that Class.forName() usually does the wrong thing. I tend to use the thread context ClassLoader, which I have set appropriately. [ July 28, 2006: Message edited by: Peter Chase ]
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Joined: Sep 12, 2005
Thanks Peter for your reply.
Just to add to this I now have the clear concept of the difference between these two.
If anyone is still confuse, he/she can go through this link. This topic extensively explained and clear many other doubts of classloading
Please DontWakeTheZombies. I am not sure that I agree with what you have written, either. But please don't continue the discussion in this thread. If you want to discuss further, please start a new thread.
(Looks like the zombie-waker has now deleted his post) [ February 29, 2008: Message edited by: Peter Chase ]