aspose file tools*
The moose likes Java in General and the fly likes Class Loading Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Class Loading Question" Watch "Class Loading Question" New topic
Author

Class Loading Question

Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134
Hi fellow ranchers
Am trying to implement a Custom Class Loader into my Weblogic App for enabling hot deployment of certain classes.
In that, as suggested by various documentation that I have read, I have overridden the findClass() method of the ClassLoader class to 'find' my class. The idea is to let loadClass() method of the ClassLoader class call my customClassLoader's findClass(). But, from the output I am getting, I don't see my class loader's findClass() method being invoked at all.
From the API, this is how loadClass() method works...
1) Calls findLoadedClass(). If class is found then returns the class
2) Calls parent's loadClass() method... until the system Class Loader's loadClass() is called or the class is loaded, whichever comes first.
3) Invokes findClass() method.
I understand for my code to work as intended, step 3) should occur on my Class Loader's findClass(). However, I dont see it happening.
This leads me to believe that probably the class I am trying to load is already being found in step 1) or 2). Can someone explain whats happening? and why my findClass() is not being invoked?


Himanshu Jhamb<br />SCJP2 v1.2 (April 2002)<br />SCJP2 v1.4 (May 2002)
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Himanshu
You can refer to IBM Tutorial on class loader and see if that helps..
Regards
Maulin
Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134
Hi,
Okay! I got over that hump... and got stuck on another.
What was happening was ... the JVM classloader was probably finding the said class already loaded and hence was not calling my findClass(). So, I changed it to point to another file ... e.g. instead of xxx.class, I gave it xxx.ini
Once that was done, I again (inside the code) pointed it back to xxx.class & that invoked my findClass(). The findClass() proceeded as expected & found the class that I wanted loaded. But, for some reason, it still did not invoke the *new* class file... but I still see the result as if the *old* xxx.class is being invoked.
Any ideas why the new one is not being loaded inside the JVM???
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'm not sure I understand, but A ClassLoader will only load a Class once. After it has been loaded it is cached in that ClassLoader forever.
I highlighted that part, since you can re-load Classes if they change by throwing away the ClassLoader that loaded them and starting a new one.
I hope that was your question.
Dave
Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134
I'm not sure I understand, but A ClassLoader will only load a Class once. After it has been loaded it is cached in that ClassLoader forever.
I highlighted that part, since you can re-load Classes if they change by throwing away the ClassLoader that loaded them and starting a new one.
--------------------------------------------------------------------------
Yes, I do undestand that. I do have a new Class Loader which I invoke from a client by sending a JMS message. While calling the new Class Loader, I pass it the class that I want reloaded. I see the new class loader being instantiated, the overridden findClass() of the new Class Loader being called, the findClass() finds my new class & returns a Class obj. after a call to defineClass(). All this is happening. But, when I run my test case, I still get the same results as if the old version of the Class file I was trying to load is present in the JVM, not the new one.
I hope I have been clear this time.
thx.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class Loading Question