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开发时,JDK已经为我们提供了一系列相应的类来实现基本的数据结构。这些类均在java.util包中。本文试图通过简单的描述,向读者阐述各个类的作用以及如何正确使用这些类。
<o:p></o:p>
Collection
├List
│├LinkedList
│├ArrayList
│└Vector ......
刚刚运行java HelloWorld.class,老是说:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/class
Caused by: java.lang.ClassNotFoundException: HelloWorld.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
  ......
一位ID为ultimus的程序员开发了一种名为anic的新语言,近日引起业界关注。根据Google Code上该项目的简介,该语言的正式名称是ANI,anic是这种语言的参考实现。
ANI是一种实验性、高性能、静态安全、完全隐含支持并行、面向对象的通用数据流编程语言。
anic用GNU工具链写成,因此可移植性很好,可以运行于所有主流操作系 ......
第一章:java对象持久化技术概述
1:持久化:persistence;对象持久化包含两方面的内容:将内存数据存入长期记忆介质并能从这些介质上无差错地复原到内存。
2:通过实现java.io包中的Serializable接口(即对象序列化和饭序列化技术)实现,这种技术很重要,虽然在执行持久化时有极大的限制,如:效率低下、不支持事务等 ......
1、 对象的初始化
(1) 非静态对象的初始化
在创建对象时,对象所在类的所有数据成员会首先进行初始化。
基本类型:int型,初始化为0。
如果为对象:这些对象会按顺序初始化。
※在所有类成员初始化完成之后,才调用本类的构造方法创建对象。
构造方法的作用就是初始化。
(2) 静态对象的初始化
程序中主类的 ......