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
相关文档:
花了两天时间,终于把access数据库里的数据换到Oracle了。当然这其中要感谢同学和博友的热心帮助拉。现将今天的收获整理下。
我用的是Oracle 10 express edition版本,这个版本建数据库挺麻烦的,所以我就直接在它自带的数据库XE下建表了。
注意:建表可一定要 ......
【IT168 技术文章】
WWJ SDK 是一种构建在 Java OpenGL (JOGL) 扩展之上的 3D
图形地球仪。WWJ 类层次结构的核心是 GLCanvas 的子类 WorldWindowGLCanvas。而 GLCanvas 是一个
Abstract Window Toolkit (AWT) 组件。
WWJ 对 AWT 的依赖性对于想在 Eclipse
应用程序中使用 WWJ 的 GIS 开发人员来讲是一个障碍。您可 ......
l组件从功能上分可分为:
1) 顶层容器:JFrame,JApplet,JDialog,JWindow
2) 中间容器:JPanel,JScrollPane,JSplitPane,JToolBar
3) 特殊容器:在GUI上起特殊作用的中间层,如JInternalFrame,JLayeredPane,JRootPane.
1.JFrame的用法
1) 用getContentPane( )方法获得JFrame的 ......
xml中键名为 英文,键值为中文,读取解析,取值实现翻译
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList; ......
Java
Reflection (JAVA反射)
Reflection 是 Java
程序开发语言的特征之一,它允许运行中的 Java
程序对自身进行检查,或者说“自审”,并能直接操作程序的内部属性。例如,使用它能获得 Java
类中各成员的名称并显示出来。
Java
的这一能力在实际应用中也许用得不是很多,但 ......