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 t ......
public class javaTest {
public static void test(String ...strings){
for(String str: strings){
System.out.print(str + " ");
}
System.out.println();
}
public static void main(String[] args){
test("a", "b", "c", "ddd");
test("a");
test("aaa", "aaadfd");
}
}
Êä³ö½á¹û
a b c ddd
a
aaa aaadfd ......
ͨ¹ý DAOFactory µÄ·ºÐÍд·¨À´ÑÝʾJava·ºÐ͵ÄÌØÊâÓ÷¨
СÐÍÏîÄ¿Öг£³£¶¼Ã»ÓÐÓÃÈý·½³Ö¾Ã»¯¿ò¼Ü£¬¶ø´ó¶¼ÊÇÓù«Ë¾»ò×ÔÐÐÒÀ¾ÝDAOģʽ·â×°µÄһЩ×é¼þÀ´Íê³ÉÊý¾Ý¿â³Ö¾Ã»¯¶¯×÷£¬²¢ÇÒ£¬Í¨³£ÎªÁ˸ü¾ß¿ÉÀ©Õ¹ÐÔ£¬³£³£Ê¹ÓóéÏ󹤳§Ä£Ê½À´½âñîºÏ¡£
Ò»¡¢ÏÈ¿´´úÂë
1¡¢¼òµ¥¹¤³§´úÂë
/*****************************************************************************/
/* Title: DAOFactory 1.0 */
/* Description: DAOFactory 1.0 Java Source Code. */
/* Copyright: Copyright(c) 2009 - CodingMouse, Inc. All rights are reserved. */
/* Company: CodingMouse's Java R&D Studio */
/* */
/* Created in August 8, 2009 */
/*****************************************************************************/
package com.china.codingmouse.cmsdk4j.dao.factory;
import java.io.Serializable;
import com.china ......
Ê×ÏÈ,AMF3ËÆºõ²¢²»Ö§³ÖList.ArrayListµÈÊý×éµÄ½âÎö...Java¿Í»§¶Ë´«µÝList¶ÔÏó,AMF3ÎÞ·¨½âÎöΪArray...
ÔÒòÊÇ:AMF3Ö»Ö§³Ö»ù´¡Êý¾ÝÀàÐÍ...
¹Ê,ÐèÒª½«ListµÈÊý¾Ýת»»ÎªObject[] !ÕâÑùAMF3²ÅÄܽ«Java´«µÝµÄÊý×é½âÎöΪArray...
ÓÉÓÚÊý×éµÄ´´½¨,¼´±ãÒ»¿ªÊ¼²»¸³Öµ,Ò²ÐèÒªÉèÖÃÊý×éµÄlength,Èç:String[] myString = new String[5];
¹Ê,ÐèÒª¶¯Ì¬´´½¨Object[]Êý×é.µ«ÍùÍù,lengthÒ»¿ªÊ¼ÊDz¢²»ÖªµÀ,±ÈÈçJDBCÖÐResultSet...
@SuppressWarnings("unchecked")
public Seed_Warehouse[] findSeedWarehouseByUserID(int userID)
throws SQLException {
String sql = "SELECT * from LESOGO_SEED_WAREHOUSE WHERE USER_ID = ?";
db.doPstm(sql, new Object[] { userID });
ResultSet rs = db.getRs();
if (rs != null) {
int i = 0; // »ñµÃÊý¾Ý¿â±íµÄÐÐÊý!
while (rs.next()) {
i++;
}
Seed_Warehouse[] sws = new Seed_Warehouse[i];
rs.beforeFirst(); // ¹â±êÖ¸ÏòÆðʼλÖÃ!
int j = 0;
while (rs.next()) {
Seed_Warehouse sw = new Seed_Warehouse();
sw.setId(rs.getInt(1));
sw.setCrop_class_name(rs.getS ......
³ýÁ˹ØÏµÐÍÊý¾Ý¿âÍ⣬»¹ÓÐkey-valueÐÍÊý¾Ý¿â¿ÉÒÔÑ¡Ôñ£¬ÔÚ´óÐ͵IJéѯϵͳÖУ¬key-valueÐÍÊý¾Ý¿â¿ÉÒÔ³öÉ«µÄÍê³ÉijЩÈÎÎñ¡£
OracleµÄBerkeley DB¾ÍÊÇÒ»ÖÖkey-valueÐÍÊý¾Ý¿â£¬±¾ÎļòÒª½éÉÜÔÚjavaÖÐʹÓÃBerkeley DB¡£
PartKey.java:
import java.io.Serializable;
public class PartKey implements Serializable
{
private String number;
public PartKey(String number) {
this.number = number;
}
public final String getNumber() {
return number;
}
public String toString() {
return "[PartKey: number=" + number + ']';
}
}
Weight.java
public class Weight implements Serializable
{
public final static String GRAMS = "grams";
public final static String OUNCES = "ounces";
private double amount;
private String units;
public Weight(double amount, String units)
{
this.amount = amount;
this.units = units;
}
public final double getAmount()
{
return amount;
}
public final String g ......
1.ʵÀý³ÉÔ±ºÍÀà³ÉÔ±
ʵÀý³ÉÔ±ÖÐÊÇÊôÓÚ¶ÔÏóµÄ,°üÀ¨ÊµÀý³ÉÔ±±äÁ¿ºÍʵÀý³ÉÔ±·½·¨,Ö»Óд´½¨Á˶ÔÏóÖ®ºó²ÅÄÜ·ÃÎÊʵÀý³ÉÔ±±äÁ¿ºÍʵÀý³ÉÔ±·½·¨.
Àà³ÉÔ±ÊÇÊôÓÚÀàµÄ,Àà³ÉÔ±ÐèÒªÓùؼü×Östatic±êʶ,Ò²³ÆÎª¾²Ì¬³ÉÔ±,Àà³ÉÔ±°üÀ¨Àà³ÉÔ±±äÁ¿ºÍÀà³ÉÔ±·½·¨,ͨ¹ýÀàÃû¿ÉÒÔÖ±½Ó·ÃÎÊÀà³ÉÔ±±äÁ¿ºÍµ÷ÓÃÀà³ÉÔ±·½·¨,¼´Ê¹Ã»Óд´½¨¶ÔÏó,Ò²Äܹ»ÒýÓÃÀà³ÉÔ±,Àà³ÉÔ±Ò²¿ÉÒÔͨ¹ý¶ÔÏóÒýÓÃ.
½ÓÏÂÀ´½²½²Àà±äÁ¿ºÍʵÀý±äÁ¿µÄÇø±ð:
£¨1£©: ÉùÃ÷µÄ²î±ð: ûÓÐʹÓÃstaticÉùÃ÷µÄΪʵÀý³ÉÔ±±äÁ¿,ÓÃstatic ÉùÃ÷µÄΪÀà³ÉÔ±±äÁ¿
£¨2£©:´æ´¢½á¹¹µÄ²î±ð: ¶ÔÓÚʵÀý±äÁ¿¶øÑÔ,Ϊÿ¸ö¶ÔÏóµÄÿ¸öʵÀý³ÉÔ±±äÁ¿·ÖÅäÒ»¸ö´æ´¢µ¥ÔªÊ¹µÃ²»Í¬¶ÔÏóµÄʵÀý³ÉÔ±±äÁ¿¾ßÓв»Í¬µÄÖµ,¶ø¶ÔÓÚÀà³ÉÔ±±äÁ¿Ö»·ÖÅäÒ»¸ö´æ´¢µ¥Ôª,ʹµÃËùÓеĶÔÏó¹²Í¬Ê¹ÓÃÒ»¸öÀà³ÉÔ±±äÁ¿.
£¨3£©:ÒýÓ÷½Ê½µÄ²î±ð: ʵÀý³ÉÔ±±äÁ¿¶ÔÓÚ¶ÔÏó,ͨ¹ý¶ÔÏó½øÐзÃÎÊ;Àà³ÉÔ±±äÁ¿ÊôÓÚÀà,¼È¿ÉÒÔͨ¹ý¶ÔÏó,Ò²¿ÉÒÔͨ¹ýÀà·ÃÎÊ.
2.equals ·½·¨½âÎö£º£¨¡¶JAVAºËÐļ¼Êõ¡·176Ò³£©
£¨1£©¶ÔÓÚ×Ö·û´®±äÁ¿À´Ëµ£¬Ê¹ÓÓ==”ºÍ“equals()”·½·¨±È½Ï×Ö·û´®Ê±£¬Æä±È½Ï·½·¨²»Í¬¡£
“==”±È½ÏÁ½¸ö±äÁ¿±¾ÉíµÄÖµ£¬¼´Á½¸ö¶ÔÏóÔÚÄÚ´æÖ ......