HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Understanding the Java Classloading Mechanism"
Vol. 8, Issue 8, p. 16

	



Listing 1

1. public class CustomClassLoader
2. extends ClassLoader {
3. //search repository
        4. private List classRepository;

5. public CustomClassLoader
6. (ClassLoader parent,String searchPath)
7. {S}

8. protected Class findClass(String

9. className) throws
10. ClassNotFoundException {
11. byte[] classBytes =
12. loadFromCustomRepository(className);
13. if(classBytes != null) {
14. return defineClass
15. (className,classBytes,0,classBytes.length);
16.    }
17. //else
18. throw new ClassNotFoundException(className);
19. }        
20. }

Listing 2

1. public Class loadClass(String name)
2. throws ClassNotFoundException
3. {    
4.    //check if the class is already loaded
5.    Class loadedClass = findLoadedClass(name);
6.    if (loadedClass == null) {
7.    //search for class in local
             8.    //repository before delegating
9.    .......      
10. //if class not found delegate to parent
11.  loadedClass = 
13. this.getClass().getClassLoader().loadClass(name);
13. }
14. return loadedClass;
15. }

 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.