The Artima Developer Community
Sponsored Link

Legacy Design Forum
Designing with Dynamic Extension

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

This techniques does not really work

Posted by Rashid Batuxi on March 06, 2000 at 4:35 PM

In the article, the class loader first loads using findLoadedClass() which always uses the system class loader. Fact is it never reaches the getClassFromHole () method in RodentClassLoader.loadClass ().

In order to make live updates, we need to be able to "reload" an existing class file on disk that has changed. Since the RodentClassLoader NEVER actually load from the "hole", it always gets the cached class in the default system loader.

In any case, by looking at the package name for custom loading, I modified the class loader to look at the "hole" first, and if the class couldn't be loaded (java.lang.Object for instance) use findLoadedClass (). This worked fine except that the cast from Mouse to Rodent now throws a ClassCastException.

Remember, to have live updates, we need to load from the "hole" every single time using our custom class loader, and we would do it by creating a new instance of the loader every time. This does work correctly, but its unusable

Also remember, the article's implementation of RodentClassLoader is "flawed" for what I am trying to do since it always used findLoadedClass() which uses the system class loader. This is cheating!

I am pasting the code below. If anyone can come up with a RodentClassLoader to make the rest of the code work I would appreciate it. I must say, this code worked fine in JDK 1.1.

Here is the code
--------------------
package loadexpt;

public class Rodent {
public void scurry() {
System.out.println("Rodent scurrying");
}
}
--------------------
--------------------
package loadexpt;

public class Mouse extends Rodent {
public void scurry() {
System.out.println("Mouse scurrying");
}
}
--------------------
--------------------
// In file dynaext/ex3/Cat.java
public class Cat {
public static void main(String[] args)
throws ClassNotFoundException, IllegalAccessException,
InstantiationException {
RodentClassLoader rcl = new RodentClassLoader();
Class c = rcl.loadClass(args[0]);
Rodent myToy = (Rodent) c.newInstance();
myToy.scurry();
}
}
--------------------




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us