Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Java URLClassLoader

Closing a URLClassLoader
By Michael McMahon
 
Complex Java programs, such as application servers, sometimes create their own class loaders using the URLClassLoader type. With URLClassLoader, applications can load classes and resources from a search path of URLs. The following URL types are supported:
file: (loads from file-system directories)
jar: (loads from JAR files)
http: (loads from http servers)
 
 
A frequent problem has been how to support updated implementations of the classes and resources loaded from a particular codebase, and in particular from JAR files. In principle, once the application clears all references to a loader object, the garbage collector and finalization mechanisms will eventually ensure that all resources (such as the JarFile objects) are released and closed.
 
The application can then replace the JAR file, and create a new URLClassLoader instance to load from the same location, but this time using the new implementation of the classes/resources.
 
However, since it can't be predicted exactly when finalization and garbage collection will occur, this causes problems for applications which need to be able to do this in a predictable and timely fashion. It is a particular problem on Windows, because open files cannot be deleted or replaced.
 
To alleviate this problem, URLClassLoader has acquired a new method called close(). It has been implemented since Build 48 of JDK7.
 
The close() method effectively invalidates the loader, so that no new classes can be loaded from it. It also closes any JAR files that were opened by the loader. This allows the application to delete or replace these files and, if necessary, create new loaders using new implementations.
 
The new method follows the familiar "Closeable" pattern, and URLClassLoader now implements the Closeable interface, which defines URLClassLoader.close(). The following sample code shows how one might use the method.
 
&n


Ïà¹ØÎĵµ£º

JavaÖ®ÔöÇ¿forÑ­»·

Óï·¨£º
for ( type ±äÁ¿Ãû£º¼¯ºÏ±äÁ¿Ãû )  { … } 
×¢ÒâÊÂÏ
µü´ú±äÁ¿±ØÐëÔÚ( )Öж¨Ò壡
¼¯ºÏ±äÁ¿¿ÉÒÔÊÇÊý×é»òʵÏÖÁËIterable½Ó¿ÚµÄ¼¯ºÏÀà
¾ÙÀý£º
public class AdvancedFor {
public static void main(String[] arg ......

Java I/O³£ÓÃÁ÷ʾÀý


package io;   
import java.io.*;   
/**  
* @author ¸ßÕíÎâÓÇ  
* ÀûÓûº³åÇøÔ­Àí,BufferedInputStream,  
* ÊµÏÖµÄÎļþ×Ö½ÚÁ÷¶ÁÈ¡¹¦ÄÜʾ·¶  
*  
*/  
public class BufferedInOutputStream {  & ......

Äã±ØÐëÖªµÀµÄ11¸öJavaµÚÈý·½Àà¿â

http://apache.freelamp.com/hadoop/hive/hive-0.4.0/
http://sourceforge.net/projects/dbunit/files/
JavaµÚÈý·½library ecosystemÊÇÒ»¸öºÜ¹ãÀ«µÄ·¶³ë¡£²»¾ÃÇ°ÓÐÈË׫ÎÄ£ºÃ¿¸öÏîÄ¿ÖУ¬Äã±ØÐëÖªµÀµÄ11¸öJavaµÚÈý·½Àà¿â¡£
µ¥Ôª²âÊÔ
1.DBUnit
DBunitÊÇÒ»¸ö»ùÓÚjunitÀ©Õ¹µÄÊý¾Ý¿â²âÊÔ¿ò¼Ü¡£ËüÌṩÁË´óÁ¿µÄÀà¶ÔÓëÊý¾Ý¿âÏ๠......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ