锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久精品国产亚洲av麻豆小说,亚洲国产精品xo在线观看,亚洲成AV人片在WWW色猫咪http://www.tkk7.com/RoyPayne/category/50508.html錛嶆暡鍑繪濇兂鐨勯敭鐩橈紝婊戝姩鐏墊劅鐨勯紶鏍囥?/description>zh-cnThu, 05 Jan 2012 19:31:21 GMTThu, 05 Jan 2012 19:31:21 GMT60Math.floor鍜孧ath.ceil http://www.tkk7.com/RoyPayne/archive/2012/01/05/367883.htmlRoyPayneRoyPayneThu, 05 Jan 2012 01:20:00 GMThttp://www.tkk7.com/RoyPayne/archive/2012/01/05/367883.htmlhttp://www.tkk7.com/RoyPayne/comments/367883.htmlhttp://www.tkk7.com/RoyPayne/archive/2012/01/05/367883.html#Feedback0http://www.tkk7.com/RoyPayne/comments/commentRss/367883.htmlhttp://www.tkk7.com/RoyPayne/services/trackbacks/367883.html
public class CeilAndFloor {
    public static void main(String[] args) {
    /*
        榪欎袱涓疂璐濆嚱鏁扮殑涓昏浠誨姟鏄埅鎺夊皬鏁頒互鍚庣殑浣嶆暟.
        鍖哄埆鏄? floor鎬繪槸鎶婃暟瀛楀彉寰楄秺鏉ヨ秺灝忥紝鑰宑eil鎬繪槸鎶婃暟瀛楀彉澶с?br />                鍏跺疄鍚嶅瓧鍙互鐞嗚Вfloor鏄湴鏉匡紝ceil鏄ぉ鑺辨澘銆?br />    
*/

        System.out.println("==============Math.floor()==============");
        System.out.println("Math.floor(99.1) = " + Math.floor(99.1));
        System.out.println("Math.floor(-99.1) = " + Math.floor(-99.1));
        System.out.println("Math.floor(99.9) = " + Math.floor(99.9));
        System.out.println("Math.floor(99.9) = " + Math.floor(-99.9));
        
        System.out.println("\n\n==============Math.ceil()==============");
        System.out.println("Math.ceil(99.1) = " + Math.ceil(99.1));
        System.out.println("Math.ceil(-99.1) = " + Math.ceil(-99.1));
        System.out.println("Math.ceil(99.9) = " + Math.ceil(99.9));
        System.out.println("Math.ceil(99.9) = " + Math.ceil(-99.9));
        
    }
}
緇撴灉
==============Math.floor()==============
Math.floor(99.1) = 99.0
Math.floor(-99.1) = -100.0
Math.floor(99.9) = 99.0
Math.floor(99.9) = -100.0

==============Math.ceil()==============
Math.ceil(99.1) = 100.0
Math.ceil(-99.1) = -99.0
Math.ceil(99.9) = 100.0
Math.ceil(99.9) = -99.0

RoyPayne 2012-01-05 09:20 鍙戣〃璇勮
]]>
鐢↗ava鑾峰緱褰撳墠鎬ц兘淇℃伅http://www.tkk7.com/RoyPayne/archive/2012/01/04/367840.htmlRoyPayneRoyPayneWed, 04 Jan 2012 06:54:00 GMThttp://www.tkk7.com/RoyPayne/archive/2012/01/04/367840.htmlhttp://www.tkk7.com/RoyPayne/comments/367840.htmlhttp://www.tkk7.com/RoyPayne/archive/2012/01/04/367840.html#Feedback0http://www.tkk7.com/RoyPayne/comments/commentRss/367840.htmlhttp://www.tkk7.com/RoyPayne/services/trackbacks/367840.html鍦↗ava涓紝鍙互鑾峰緱鎬葷殑鐗╃悊鍐呭瓨銆佸墿浣欑殑鐗╃悊鍐呭瓨銆佸凡浣跨敤鐨勭墿鐞嗗唴瀛樼瓑淇℃伅錛屾湰渚嬭瑙e浣曞彇寰楄繖浜涗俊鎭紝騫朵笖鑾峰緱鍦╓indows涓嬬殑鍐呭瓨浣跨敤鐜囥?/span>
     棣栧厛緙栧啓涓涓狹onitorInfoBean綾伙紝鐢ㄦ潵瑁呰澆鐩戞帶鐨勪竴浜涗俊鎭紝鍖呮嫭鐗╃悊鍐呭瓨銆佸墿浣欑殑鐗╃悊鍐呭瓨銆佸凡浣跨敤鐨勭墿鐞嗗唴瀛樸佸唴瀛樹嬌鐢ㄧ巼絳夊瓧孌碉紝璇ョ被鐨勪唬鐮佸涓嬶細
      

package com.amigo.performance;

/**
 * 鐩戣淇℃伅鐨凧avaBean綾?
 * 
@author <a href="mailto:xiexingxing1121@126.com">AmigoXie</a>
 * 
@version 1.0 
 * Creation date: 2008-4-25 - 涓婂崍10:37:00
 
*/
public class MonitorInfoBean {
    /** 鍙嬌鐢ㄥ唴瀛? */
    private long totalMemory;
    
    /** 鍓╀綑鍐呭瓨. */
    private long freeMemory;
    
    /** 鏈澶у彲浣跨敤鍐呭瓨. */
    private long maxMemory;
    
    /** 鎿嶄綔緋葷粺. */
    private String osName;
    
    /** 鎬葷殑鐗╃悊鍐呭瓨. */
    private long totalMemorySize;
    
    /** 鍓╀綑鐨勭墿鐞嗗唴瀛? */
    private long freePhysicalMemorySize;
    
    /** 宸蹭嬌鐢ㄧ殑鐗╃悊鍐呭瓨. */
    private long usedMemory;
    
    /** 綰跨▼鎬繪暟. */
    private int totalThread;
    
    /** cpu浣跨敤鐜? */
    private double cpuRatio;

    public long getFreeMemory() {
        return freeMemory;
    }

    public void setFreeMemory(long freeMemory) {
        this.freeMemory = freeMemory;
    }

    public long getFreePhysicalMemorySize() {
        return freePhysicalMemorySize;
    }

    public void setFreePhysicalMemorySize(long freePhysicalMemorySize) {
        this.freePhysicalMemorySize = freePhysicalMemorySize;
    }

    public long getMaxMemory() {
        return maxMemory;
    }

    public void setMaxMemory(long maxMemory) {
        this.maxMemory = maxMemory;
    }

    public String getOsName() {
        return osName;
    }

    public void setOsName(String osName) {
        this.osName = osName;
    }

    public long getTotalMemory() {
        return totalMemory;
    }

    public void setTotalMemory(long totalMemory) {
        this.totalMemory = totalMemory;
    }

    public long getTotalMemorySize() {
        return totalMemorySize;
    }

    public void setTotalMemorySize(long totalMemorySize) {
        this.totalMemorySize = totalMemorySize;
    }

    public int getTotalThread() {
        return totalThread;
    }

    public void setTotalThread(int totalThread) {
        this.totalThread = totalThread;
    }

    public long getUsedMemory() {
        return usedMemory;
    }

    public void setUsedMemory(long usedMemory) {
        this.usedMemory = usedMemory;
    }

    public double getCpuRatio() {
        return cpuRatio;
    }

    public void setCpuRatio(double cpuRatio) {
        this.cpuRatio = cpuRatio;
    }
}

鎺ョ潃緙栧啓涓涓幏寰楀綋鍓嶇殑鐩戞帶淇℃伅鐨勬帴鍙o紝璇ョ被鐨勪唬鐮佸涓嬫墍紺猴細

package com.amigo.performance;

/**
 * 鑾峰彇緋葷粺淇℃伅鐨勪笟鍔¢昏緫綾繪帴鍙?
 * 
@author <a href="mailto:xiexingxing1121@126.com">AmigoXie</a>
 * 
@version 1.0 
 * Creation date: 2008-3-11 - 涓婂崍10:06:06
 
*/
public interface IMonitorService {
    /**
     * 鑾峰緱褰撳墠鐨勭洃鎺у璞?
     * 
@return 榪斿洖鏋勯犲ソ鐨勭洃鎺у璞?br />     * @throws Exception
     * 
@author <a href="mailto:xiexingxing1121@126.com">AmigoXie</a>
     * Creation date: 2008-4-25 - 涓婂崍10:45:08
     
*/
    public MonitorInfoBean getMonitorInfoBean() throws Exception;

}

璇ョ被鐨勫疄鐜扮被MonitorServiceImpl濡備笅鎵紺猴細


package com.amigo.performance;

import java.io.InputStreamReader;
import java.io.LineNumberReader;

import sun.management.ManagementFactory;

import com.sun.management.OperatingSystemMXBean;

/**
 * 鑾峰彇緋葷粺淇℃伅鐨勪笟鍔¢昏緫瀹炵幇綾?
 * 
@author <a href="mailto:xiexingxing1121@126.com">AmigoXie</a>
 * 
@version 1.0 Creation date: 2008-3-11 - 涓婂崍10:06:06
 
*/
public class MonitorServiceImpl implements IMonitorService {
    
    private static final int CPUTIME = 30;

    private static final int PERCENT = 100;

    private static final int FAULTLENGTH = 10;

    /**
     * 鑾峰緱褰撳墠鐨勭洃鎺у璞?
     * 
@return 榪斿洖鏋勯犲ソ鐨勭洃鎺у璞?br />     * @throws Exception
     * 
@author <a href="mailto:xiexingxing1121@126.com">AmigoXie</a>
     * Creation date: 2008-4-25 - 涓婂崍10:45:08
     
*/
    public MonitorInfoBean getMonitorInfoBean() throws Exception {
        int kb = 1024;
        
        // 鍙嬌鐢ㄥ唴瀛?/span>
        long totalMemory = Runtime.getRuntime().totalMemory() / kb;
        // 鍓╀綑鍐呭瓨
        long freeMemory = Runtime.getRuntime().freeMemory() / kb;
        // 鏈澶у彲浣跨敤鍐呭瓨
        long maxMemory = Runtime.getRuntime().maxMemory() / kb;

        OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory
                .getOperatingSystemMXBean();

        // 鎿嶄綔緋葷粺
        String osName = System.getProperty("os.name");
        // 鎬葷殑鐗╃悊鍐呭瓨
        long totalMemorySize = osmxb.getTotalPhysicalMemorySize() / kb;
        // 鍓╀綑鐨勭墿鐞嗗唴瀛?/span>
        long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize() / kb;
        // 宸蹭嬌鐢ㄧ殑鐗╃悊鍐呭瓨
        long usedMemory = (osmxb.getTotalPhysicalMemorySize() - osmxb
                .getFreePhysicalMemorySize())
                / kb;

        // 鑾峰緱綰跨▼鎬繪暟
        ThreadGroup parentThread;
        for (parentThread = Thread.currentThread().getThreadGroup(); parentThread
                .getParent() != null; parentThread = parentThread.getParent())
            ;
        int totalThread = parentThread.activeCount();

        double cpuRatio = 0;
        if (osName.toLowerCase().startsWith("windows")) {
            cpuRatio = this.getCpuRatioForWindows();
        }
        
        // 鏋勯犺繑鍥炲璞?/span>
        MonitorInfoBean infoBean = new MonitorInfoBean();
        infoBean.setFreeMemory(freeMemory);
        infoBean.setFreePhysicalMemorySize(freePhysicalMemorySize);
        infoBean.setMaxMemory(maxMemory);
        infoBean.setOsName(osName);
        infoBean.setTotalMemory(totalMemory);
        infoBean.setTotalMemorySize(totalMemorySize);
        infoBean.setTotalThread(totalThread);
        infoBean.setUsedMemory(usedMemory);
        infoBean.setCpuRatio(cpuRatio);
        return infoBean;
    }

    /**
     * 鑾峰緱CPU浣跨敤鐜?
     * 
@return 榪斿洖cpu浣跨敤鐜?br />     * @author <a href="mailto:xiexingxing1121@126.com">AmigoXie</a>
     * Creation date: 2008-4-25 - 涓嬪崍06:05:11
     
*/
    private double getCpuRatioForWindows() {
        try {
            String procCmd = System.getenv("windir")
                    + "\\system32\\wbem\\wmic.exe process get Caption,CommandLine,"
                    + "KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount";
            // 鍙栬繘紼嬩俊鎭?/span>
            long[] c0 = readCpu(Runtime.getRuntime().exec(procCmd));
            Thread.sleep(CPUTIME);
            long[] c1 = readCpu(Runtime.getRuntime().exec(procCmd));
            if (c0 != null && c1 != null) {
                long idletime = c1[0] - c0[0];
                long busytime = c1[1] - c0[1];
                return Double.valueOf(
                        PERCENT * (busytime) / (busytime + idletime))
                        .doubleValue();
            } else {
                return 0.0;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return 0.0;
        }
    }

    /**
     * 璇誨彇CPU淇℃伅.
     * 
@param proc
     * 
@return
     * 
@author <a href="mailto:xiexingxing1121@126.com">AmigoXie</a>
     * Creation date: 2008-4-25 - 涓嬪崍06:10:14
     
*/
    private long[] readCpu(final Process proc) {
        long[] retn = new long[2];
        try {
            proc.getOutputStream().close();
            InputStreamReader ir = new InputStreamReader(proc.getInputStream());
            LineNumberReader input = new LineNumberReader(ir);
            String line = input.readLine();
            if (line == null || line.length() < FAULTLENGTH) {
                return null;
            }
            int capidx = line.indexOf("Caption");
            int cmdidx = line.indexOf("CommandLine");
            int rocidx = line.indexOf("ReadOperationCount");
            int umtidx = line.indexOf("UserModeTime");
            int kmtidx = line.indexOf("KernelModeTime");
            int wocidx = line.indexOf("WriteOperationCount");
            long idletime = 0;
            long kneltime = 0;
            long usertime = 0;
            while ((line = input.readLine()) != null) {
                if (line.length() < wocidx) {
                    continue;
                }
                // 瀛楁鍑虹幇欏哄簭錛欳aption,CommandLine,KernelModeTime,ReadOperationCount,
                
// ThreadCount,UserModeTime,WriteOperation
                String caption = Bytes.substring(line, capidx, cmdidx - 1)
                        .trim();
                String cmd = Bytes.substring(line, cmdidx, kmtidx - 1).trim();
                if (cmd.indexOf("wmic.exe") >= 0) {
                    continue;
                }
                // log.info("line="+line);
                if (caption.equals("System Idle Process")
                        || caption.equals("System")) {
                    idletime += Long.valueOf(
                            Bytes.substring(line, kmtidx, rocidx - 1).trim())
                            .longValue();
                    idletime += Long.valueOf(
                            Bytes.substring(line, umtidx, wocidx - 1).trim())
                            .longValue();
                    continue;
                }

                kneltime += Long.valueOf(
                        Bytes.substring(line, kmtidx, rocidx - 1).trim())
                        .longValue();
                usertime += Long.valueOf(
                        Bytes.substring(line, umtidx, wocidx - 1).trim())
                        .longValue();
            }
            retn[0] = idletime;
            retn[1] = kneltime + usertime;
            return retn;
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                proc.getInputStream().close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
    
    /**
     * 嫻嬭瘯鏂規硶.
     * 
@param args
     * 
@throws Exception
     * 
@author <a href="mailto:xiexingxing1121@126.com">AmigoXie</a>
     * Creation date: 2008-4-30 - 涓嬪崍04:47:29
     
*/
    public static void main(String[] args) throws Exception {
        IMonitorService service = new MonitorServiceImpl();
        MonitorInfoBean monitorInfo = service.getMonitorInfoBean();
        System.out.println("cpu鍗犳湁鐜?" + monitorInfo.getCpuRatio());
        
        System.out.println("鍙嬌鐢ㄥ唴瀛?" + monitorInfo.getTotalMemory());
        System.out.println("鍓╀綑鍐呭瓨=" + monitorInfo.getFreeMemory());
        System.out.println("鏈澶у彲浣跨敤鍐呭瓨=" + monitorInfo.getMaxMemory());
        
        System.out.println("鎿嶄綔緋葷粺=" + monitorInfo.getOsName());
        System.out.println("鎬葷殑鐗╃悊鍐呭瓨=" + monitorInfo.getTotalMemorySize() + "kb");
        System.out.println("鍓╀綑鐨勭墿鐞嗗唴瀛?" + monitorInfo.getFreeMemory() + "kb");
        System.out.println("宸蹭嬌鐢ㄧ殑鐗╃悊鍐呭瓨=" + monitorInfo.getUsedMemory() + "kb");
        System.out.println("綰跨▼鎬繪暟=" + monitorInfo.getTotalThread() + "kb");
    }
}

璇ュ疄鐜扮被涓渶瑕佺敤鍒頒竴涓嚜宸辯紪鍐檅yte鐨勫伐鍏風被錛岃綾葷殑浠g爜濡備笅鎵紺猴細


package com.amigo.performance;

/**
 * byte鎿嶄綔綾?
 * 
@author <a href="mailto:xiexingxing1121@126.com">AmigoXie</a>
 * 
@version 1.0 
 * Creation date: 2008-4-30 - 涓嬪崍04:57:23
 
*/
public class Bytes {
    /**
     * 鐢變簬String.subString瀵規眽瀛楀鐞嗗瓨鍦ㄩ棶棰橈紙鎶婁竴涓眽瀛楄涓轟竴涓瓧鑺?錛屽洜姝ゅ湪
     * 鍖呭惈姹夊瓧鐨勫瓧絎︿覆鏃跺瓨鍦ㄩ殣鎮o紝鐜拌皟鏁村涓嬶細
     * 
@param src 瑕佹埅鍙栫殑瀛楃涓?br />     * @param start_idx 寮濮嬪潗鏍囷紙鍖呮嫭璇ュ潗鏍?
     * 
@param end_idx   鎴鍧愭爣錛堝寘鎷鍧愭爣錛?br />     * @return
     
*/
    public static String substring(String src, int start_idx, int end_idx){
        byte[] b = src.getBytes();
        String tgt = "";
        for(int i=start_idx; i<=end_idx; i++){
            tgt +=(char)b[i];
        }
        return tgt;
    }
}

榪愯涓婱onitorBeanImpl綾伙紝璇昏呭皢浼氱湅鍒板綋鍓嶇殑鍐呭瓨銆乧pu鍒╃敤鐜囩瓑淇℃伅銆?/span>













RoyPayne 2012-01-04 14:54 鍙戣〃璇勮
]]>
java 閫氳繃System.getProperties()鑾峰彇緋葷粺鍙傛暟http://www.tkk7.com/RoyPayne/archive/2012/01/04/367837.htmlRoyPayneRoyPayneWed, 04 Jan 2012 06:37:00 GMThttp://www.tkk7.com/RoyPayne/archive/2012/01/04/367837.htmlhttp://www.tkk7.com/RoyPayne/comments/367837.htmlhttp://www.tkk7.com/RoyPayne/archive/2012/01/04/367837.html#Feedback0http://www.tkk7.com/RoyPayne/comments/commentRss/367837.htmlhttp://www.tkk7.com/RoyPayne/services/trackbacks/367837.html闃呰鍏ㄦ枃

RoyPayne 2012-01-04 14:37 鍙戣〃璇勮
]]>
ListResourceBundlehttp://www.tkk7.com/RoyPayne/archive/2012/01/04/367835.htmlRoyPayneRoyPayneWed, 04 Jan 2012 06:29:00 GMThttp://www.tkk7.com/RoyPayne/archive/2012/01/04/367835.htmlhttp://www.tkk7.com/RoyPayne/comments/367835.htmlhttp://www.tkk7.com/RoyPayne/archive/2012/01/04/367835.html#Feedback0http://www.tkk7.com/RoyPayne/comments/commentRss/367835.htmlhttp://www.tkk7.com/RoyPayne/services/trackbacks/367835.html    ListResourceBundle 鏄?nbsp;ResourceBundle 鐨勪竴涓娊璞$被錛岀敤浜庣鐞嗘柟渚胯屽張鏄撲簬浣跨敤鐨勫垪琛ㄤ腑鐨勮璦鐜璧勬簮銆傛湁鍏寵祫婧愬寘鐨勫父瑙勪俊鎭紝璇峰弬闃?nbsp;ResourceBundle銆?br />    瀛愮被蹇呴』閲嶅啓 getContents 騫舵彁渚涗竴涓暟緇勶紝鍏朵腑鏁扮粍涓殑姣忎釜欏歸兘鏄竴涓璞″銆傛瘡瀵圭殑絎竴涓厓绱犳槸閿紝璇ラ敭蹇呴』鏄竴涓?nbsp;String錛屽茍涓旂浜屼釜鍏冪礌鏄拰璇ラ敭鐩稿叧鑱旂殑鍊箋?br />      涓嬮潰鐨?/span>紺轟緥鏄劇ず浜嗗叿鏈夊熀鏈悕縐?"MyResources" 鐨勮祫婧愬寘緋誨垪鐨勪袱涓垚鍛樸?MyResources" 鏄祫婧愬寘緋誨垪鐨勯粯璁ゆ垚鍛橈紝"MyResources_fr" 鏄?French 鎴愬憳銆傝繖浜涙垚鍛樻槸鍩轟簬ListResourceBundle錛堜竴涓浉鍏崇殑紺轟緥鏄劇ず浜嗗浣曟妸涓涓祫婧愬寘娣誨姞鍒板熀浜庡睘鎬ф枃浠剁殑姝ょ郴鍒楋級銆傛紺轟緥涓殑閿艦寮忎負 "s1" 絳夈傚疄闄呯殑閿畬鍏ㄥ彇鍐充簬鎮ㄧ殑閫夋嫨錛屽彧瑕佸畠浠拰紼嬪簭涓敤浜庝粠璧勬簮鍖呬腑鑾峰彇瀵硅薄鐨勯敭鐩稿悓銆傞敭鍖哄垎澶у皬鍐欍?br />     

public class MyResources extends ListResourceBundle {
     protected Object[][] getContents() {
         return new Object[][] = {
     // LOCALIZE THIS
         {"s1", "The disk \"{1}\" contains {0}."},  // MessageFormat pattern
         {"s2", "1"},                               // location of {0} in pattern
         {"s3", "My Disk"},                         // sample disk name
         {"s4", "no files"},                        // first ChoiceFormat choice
         {"s5", "one file"},                        // second ChoiceFormat choice
         {"s6", "{0,number} files"},                // third ChoiceFormat choice
         {"s7", "3 Mar 96"},                        // sample date
         {"s8", new Dimension(1,5)}                 // real object, not just string
     
// END OF MATERIAL TO LOCALIZE
     };
   }
 }

 public class MyResources_fr extends ListResourceBundle {
     protected Object[][] getContents() {
         return new Object[][] = {
     // LOCALIZE THIS
         {"s1", "Le disque \"{1}\" {0}."},          // MessageFormat pattern
         {"s2", "1"},                               // location of {0} in pattern
         {"s3", "Mon disque"},                      // sample disk name
         {"s4", "ne contient pas de fichiers"},     // first ChoiceFormat choice
         {"s5", "contient un fichier"},             // second ChoiceFormat choice
         {"s6", "contient {0,number} fichiers"},    // third ChoiceFormat choice
         {"s7", "3 mars 1996"},                     // sample date
         {"s8", new Dimension(1,3)}                 // real object, not just string
     
// END OF MATERIAL TO LOCALIZE
     };
   }
}


RoyPayne 2012-01-04 14:29 鍙戣〃璇勮
]]>
classloaderhttp://www.tkk7.com/RoyPayne/archive/2011/12/30/367567.htmlRoyPayneRoyPayneFri, 30 Dec 2011 04:07:00 GMThttp://www.tkk7.com/RoyPayne/archive/2011/12/30/367567.htmlhttp://www.tkk7.com/RoyPayne/comments/367567.htmlhttp://www.tkk7.com/RoyPayne/archive/2011/12/30/367567.html#Feedback0http://www.tkk7.com/RoyPayne/comments/commentRss/367567.htmlhttp://www.tkk7.com/RoyPayne/services/trackbacks/367567.html

What is ClassLoader?
   
   涓庢櫘閫氱▼搴忎笉鍚岀殑鏄紝Java紼嬪簭錛坈lass鏂囦歡錛夊茍涓嶆槸鏈湴鐨勫彲鎵ц紼嬪簭銆傚綋榪愯Java紼嬪簭鏃訛紝棣栧厛榪愯JVM錛圝ava铏氭嫙鏈猴級錛岀劧鍚庡啀鎶奐ava class鍔犺澆鍒癑VM閲屽ご榪愯錛岃礋璐e姞杞絁ava class鐨勮繖閮ㄥ垎灝卞彨鍋欳lass Loader銆?/span>

銆銆JVM鏈韓鍖呭惈浜嗕竴涓狢lassLoader縐頒負Bootstrap ClassLoader錛屽拰JVM涓鏍鳳紝BootstrapClassLoader鏄敤鏈湴浠g爜瀹炵幇鐨勶紝瀹冭礋璐e姞杞芥牳蹇僇avaClass錛堝嵆鎵鏈塲ava.*寮澶寸殑綾伙級銆傚彟澶朖VM榪樹細鎻愪緵涓や釜ClassLoader錛屽畠浠兘鏄敤Java璇█緙栧啓鐨勶紝鐢盉ootstrapClassLoader鍔犺澆錛涘叾涓璄xtension ClassLoader璐熻矗鍔犺澆鎵╁睍鐨凧avaclass錛堜緥濡傛墍鏈塲avax.*寮澶寸殑綾誨拰瀛樻斁鍦↗RE鐨別xt鐩綍涓嬬殑綾伙級錛孉pplicationClassLoader璐熻矗鍔犺澆搴旂敤紼嬪簭鑷韓鐨勭被銆?/span>
銆銆褰撹繍琛屼竴涓▼搴忕殑鏃跺欙紝JVM鍚姩錛岃繍琛宐ootstrapclassloader錛岃ClassLoader鍔犺澆java鏍稿績API錛圗xtClassLoader鍜孉ppClassLoader涔熷湪姝ゆ椂琚姞杞斤級錛岀劧鍚庤皟鐢‥xtClassLoader鍔犺澆鎵╁睍API錛屾渶鍚嶢ppClassLoader鍔犺澆CLASSPATH鐩綍涓嬪畾涔夌殑Class錛岃繖灝辨槸涓涓▼搴忔渶鍩烘湰鐨勫姞杞芥祦紼嬨?/span>
銆銆娉? 瀛lassLoader鐪婳SGI

When to load the class?

浠涔堟椂鍊橨VM浼氫嬌鐢–lassLoader鍔犺澆涓涓被鍛紵褰撲綘浣跨敤java鍘繪墽琛屼竴涓被錛孞VM浣跨敤ApplicationClassLoader鍔犺澆榪欎釜綾伙紱鐒跺悗濡傛灉綾籄寮曠敤浜嗙被B錛屼笉綆℃槸鐩存帴寮曠敤榪樻槸鐢–lass.forName()寮曠敤錛孞VM灝變細鎵懼埌鍔犺澆綾籄鐨凜lassLoader錛屽茍鐢ㄨ繖涓狢lassLoader鏉ュ姞杞界被B銆侸VM鎸夌収榪愯鏃剁殑鏈夋晥鎵ц璇彞錛屾潵鍐沖畾鏄惁闇瑕佽杞芥柊綾伙紝浠庤岃杞藉敖鍙兘灝戠殑綾伙紝榪欎竴鐐瑰拰緙栬瘧綾繪槸涓嶇浉鍚岀殑銆?/span>
銆銆Why use your own ClassLoader?
銆銆浼間箮JVM鑷韓鐨凜lassLoader宸茬粡瓚沖浜嗭紝涓轟粈涔堟垜浠繕闇瑕佸垱寤鴻嚜宸辯殑ClassLoader鍛紵
銆銆鍥犱負JVM鑷甫鐨凜lassLoader鍙槸鎳傚緱浠庢湰鍦版枃浠剁郴緇熷姞杞芥爣鍑嗙殑java class鏂囦歡錛屽鏋滅紪鍐欎綘鑷繁鐨凜lassLoader錛屼綘鍙互鍋氬埌錛?/span>
銆銆1錛夊湪鎵ц闈炵疆淇′唬鐮佷箣鍓嶏紝鑷姩楠岃瘉鏁板瓧絳懼悕
銆銆2錛夊姩鎬佸湴鍒涘緩絎﹀悎鐢ㄦ埛鐗瑰畾闇瑕佺殑瀹氬埗鍖栨瀯寤虹被
銆銆3錛変粠鐗瑰畾鐨勫満鎵鍙栧緱java class錛屼緥濡傛暟鎹簱涓?/span>
銆銆4) 絳夌瓑
銆銆浜嬪疄涓婂綋浣跨敤Applet鐨勬椂鍊欙紝灝辯敤鍒頒簡鐗瑰畾鐨凜lassLoader錛屽洜涓鴻繖鏃墮渶瑕佷粠緗戠粶涓婂姞杞絡ava class錛屽茍涓旇媯鏌ョ浉鍏崇殑瀹夊叏淇℃伅銆?/span>
銆銆鐩墠鐨勫簲鐢ㄦ湇鍔″櫒澶ч兘浣跨敤浜咰lassLoader鎶鏈紝鍗充嬌浣犱笉闇瑕佸垱寤鴻嚜宸辯殑ClassLoader錛屼簡瑙e叾鍘熺悊涔熸湁鍔╀簬鏇村ソ鍦伴儴緗茶嚜宸辯殑搴旂敤銆?br />

ClassLoader Tree & Delegation Model

褰撲綘鍐沖畾鍒涘緩浣犺嚜宸辯殑ClassLoader鏃訛紝闇瑕佺戶鎵縥ava.lang.ClassLoader鎴栬呭畠鐨勫瓙綾匯傚湪瀹炰緥鍖栨瘡涓狢lassLoader瀵硅薄鏃訛紝闇瑕佹寚瀹氫竴涓埗瀵硅薄錛涘鏋滄病鏈夋寚瀹氱殑璇濓紝緋葷粺鑷姩鎸囧畾ClassLoader.getSystemClassLoader()涓虹埗瀵硅薄銆?/span>
銆銆鎵浠ュ綋鍒涘緩鑷繁鐨凜lass Loader鏃訛紝鍙渶瑕侀噸杞絝indClass()榪欎釜鏂規硶銆?br />

Unloading? Reloading?

褰撲竴涓猨avaclass琚姞杞藉埌JVM涔嬪悗錛屽畠鏈夋病鏈夊彲鑳借鍗歌澆鍛紵鎴戜滑鐭ラ亾Win32鏈塅reeLibrary()鍑芥暟錛孭osix鏈塪lclose()鍑芥暟鍙互琚皟鐢ㄦ潵鍗歌澆鎸囧畾鐨勫姩鎬佽繛鎺ュ簱錛屼絾鏄疛ava騫舵病鏈夋彁渚涗竴涓猆nloadClass()鐨勬柟娉曟潵鍗歌澆鎸囧畾鐨勭被銆?/span>
銆銆鍦↗ava涓紝java class鐨勫嵏杞戒粎浠呮槸涓縐嶅緋葷粺鐨勪紭鍖栵紝鏈夊姪浜庡噺灝戝簲鐢ㄥ鍐呭瓨鐨勫崰鐢ㄣ傛棦鐒舵槸涓縐嶄紭鍖栨柟娉曪紝閭d箞灝卞畬鍏ㄦ槸JVM鑷鍐沖畾濡備綍瀹炵幇錛屽Java寮鍙戜漢鍛樻潵璇存槸瀹屽叏閫忔槑鐨勩?/span>
銆銆鍦ㄤ粈涔堟椂鍊欎竴涓猨ava class/interface浼氳鍗歌澆鍛紵Sun鍏徃鐨勫師璇濇槸榪欎箞璇寸殑錛?class or interfacemay be unloaded if and only if its class loader is unreachable. Classesloaded by the bootstrap loader may not be unloaded."
銆銆浜嬪疄涓婃垜浠叧蹇冪殑涓嶆槸濡備綍鍗歌澆綾葷殑錛屾垜浠叧蹇冪殑鏄浣曟洿鏂板凡緇忚鍔犺澆浜嗙殑綾諱粠鑰屾洿鏂板簲鐢ㄧ殑鍔熻兘銆侸SP鍒欐槸涓涓潪甯稿吀鍨嬬殑渚嬪瓙錛屽鏋滀竴涓狫SP鏂囦歡琚洿鏀逛簡錛屽簲鐢ㄦ湇鍔″櫒鍒欓渶瑕佹妸鏇存敼鍚庣殑JSP閲嶆柊緙栬瘧錛岀劧鍚庡姞杞芥柊鐢熸垚鐨勭被鏉ュ搷搴斿悗緇х殑璇鋒眰銆?/span>
銆銆鍏跺疄涓涓凡緇忓姞杞界殑綾繪槸鏃犳硶琚洿鏂扮殑錛屽鏋滀綘璇曞浘鐢ㄥ悓涓涓狢lassLoader鍐嶆鍔犺澆鍚屼竴涓被錛屽氨浼氬緱鍒板紓甯革紙java.lang.LinkageError: duplicate classdefinition錛夛紝鎴戜滑鍙兘澶熼噸鏂板垱寤轟竴涓柊鐨凜lassLoader瀹炰緥鏉ュ啀嬈″姞杞芥柊綾匯傝嚦浜庡師鏉ュ凡緇忓姞杞界殑綾伙紝寮鍙戜漢鍛樹笉蹇呭幓綆″畠錛屽洜涓哄畠鍙兘榪樻湁瀹炰緥姝e湪琚嬌鐢紝鍙鐩稿叧鐨勫疄渚嬮兘琚唴瀛樺洖鏀朵簡錛岄偅涔圝VM灝變細鍦ㄩ傚綋鐨勬椂鍊欐妸涓嶄細鍐嶄嬌鐢ㄧ殑綾誨嵏杞姐?/span>
銆銆浣跨敤綰跨▼涓婁笅鏂囩被鍔犺澆鍣? 鍙互鍦ㄦ墽琛岀嚎紼嬩腑, 鎶涘純鍙屼翰濮旀淳鍔犺澆閾炬ā寮? 浣跨敤綰跨▼涓婁笅鏂囬噷鐨勭被鍔犺澆鍣ㄥ姞杞界被.
銆銆鍏稿瀷鐨勪緥瀛愭湁, 閫氳繃綰跨▼涓婁笅鏂囨潵鍔犺澆絎笁鏂瑰簱jndi瀹炵幇, 鑰屼笉渚濊禆浜庡弻浜插媧?
銆銆澶ч儴鍒唈ava app鏈嶅姟鍣?jboss, tomcat..)涔熸槸閲囩敤contextClassLoader鏉ュ鐞唚eb鏈嶅姟銆?/span>
銆銆褰撶劧, 濂戒笢瑗塊兘鏈夊埄寮? 浣跨敤綰跨▼涓婁笅鏂囧姞杞界被, 涔熻娉ㄦ剰, 淇濊瘉澶氭牴闇瑕侀氫俊鐨勭嚎紼嬮棿鐨勭被鍔犺澆鍣ㄥ簲璇ユ槸鍚屼竴涓? 闃叉鍥犱負涓嶅悓鐨勭被鍔犺澆鍣? 瀵艱嚧綾誨瀷杞崲寮傚父(ClassCastException).
銆銆鍙傝冭祫鏂欏強鍥劇墖鏉ユ簮——Understanding J2EE Application Server Class Loading Architectures



RoyPayne 2011-12-30 12:07 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 色播精品免费小视频| 在线观看特色大片免费网站| 国产精品69白浆在线观看免费| 亚洲大尺度无码专区尤物| 99久久99这里只有免费的精品| 亚洲国产人成中文幕一级二级| 全部一级一级毛片免费看| 午夜亚洲国产成人不卡在线| 一级毛片免费播放试看60分钟| avtt亚洲天堂| 精品视频一区二区三区免费| 亚洲AV无码久久精品狠狠爱浪潮| 久久久久久久99精品免费观看| 亚洲国产精品第一区二区| 97在线视频免费| 中文字幕亚洲码在线| 俄罗斯极品美女毛片免费播放| 成年大片免费高清在线看黄| 亚洲宅男天堂在线观看无病毒 | 特级无码毛片免费视频| 亚洲综合激情另类专区| 在线观看人成视频免费无遮挡| 亚洲人成电影福利在线播放| 可以免费看黄的网站| mm1313亚洲国产精品无码试看| 亚洲人成国产精品无码| 亚洲高清免费在线观看| 亚洲av无码成人影院一区| 亚洲熟妇无码八AV在线播放| 国产大片91精品免费观看不卡| 精品亚洲av无码一区二区柚蜜| 亚洲人成77777在线播放网站| 免费看又黄又无码的网站| 国产亚洲玖玖玖在线观看| 亚洲精品无码专区2| 99久久99久久精品免费观看| 亚洲成aⅴ人片久青草影院按摩| 亚洲尤码不卡AV麻豆| a级毛片无码免费真人| a级毛片黄免费a级毛片| 亚洲精品无码专区在线|