锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久se精品一区二区影院 ,久久精品国产精品国产精品污,99久久国产免费福利http://www.shnenglu.com/misschuer/category/21096.htmlzh-cnMon, 18 May 2015 10:57:15 GMTMon, 18 May 2015 10:57:15 GMT60瀵硅薄姹?濂楃敤浜嗙綉涓婄殑涓涓湁BUG浠g爜 鑷繁琛ュ厖鐨?娌″疄闄呯敤榪?http://www.shnenglu.com/misschuer/archive/2015/05/18/210686.html姝ゆ渶鐩告?/dc:creator>姝ゆ渶鐩告?/author>Mon, 18 May 2015 10:49:00 GMThttp://www.shnenglu.com/misschuer/archive/2015/05/18/210686.htmlhttp://www.shnenglu.com/misschuer/comments/210686.htmlhttp://www.shnenglu.com/misschuer/archive/2015/05/18/210686.html#Feedback0http://www.shnenglu.com/misschuer/comments/commentRss/210686.htmlhttp://www.shnenglu.com/misschuer/services/trackbacks/210686.htmlimport java.util.Enumeration;
import java.util.Vector;

public class ObjectPool {

    private static final boolean PRINTABLE = true;
    private Class<?> clazz = null;
    private int numObjects = 10;
    private int maxObjects = 50;
    private Vector<PooledObject> objects = null;
    
    public static void main(String[] args) throws Exception {

        ObjectPool pool = new ObjectPool(XX.class);
        pool.createPool();
        
        XX xx = (XX) pool.getObject();
        xx.reset();
        xx.setAge(1);
        xx.setSex("M");
        
        pool.returnObject(xx);
        pool.closeObjectPool();
    }
    
    
    public ObjectPool(Class<?> clazz) {
        
        this.clazz = clazz;
    }
    
    public synchronized void createPool() throws Exception {
        
        if (this.objects != null)
            return;
        
        this.objects = new Vector<PooledObject>();
        for (int i = 0; i < this.numObjects; ++ i) {
            
            createObjects();
        }
    }
    
    
    public synchronized Object getObject() throws Exception {
        
        if (this.objects == null)
            return null;
        
        Object conn = this.getFreeObject();
        
        while (conn == null) {
            wait(250);
            conn = this.getFreeObject();
        }
        
        return conn;
    }
    
    
    private Object getFreeObject() throws Exception {
        
        Object obj = this.findFreeObject();
        
        if (obj == null) {
            
            this.createObjects();
            obj = this.findFreeObject();
            if (obj == null) {
                
                return null;
            }
        }
        
        return obj;
    }
    
    private void createObjects() throws Exception {
        
        if (this.objects.size() < this.maxObjects) {
            
            this.message("created" + this.objects.size());
            Object obj = this.clazz.newInstance();
            this.objects.addElement(new PooledObject(this.objects.size(), obj));
        }
    }
    
    
    private Object findFreeObject() {
        
        this.message("before free:--------");
        this.print();
        Object obj = null;
        PooledObject pooledObject = null;
        Enumeration<PooledObject> enumerate = objects.elements();
        while (enumerate.hasMoreElements()) {
            
            pooledObject = (PooledObject) enumerate.nextElement();
            if (!pooledObject.isBusy()) {
                
                pooledObject.setBusy(true);
                obj = pooledObject.getObject();
                this.message("free object");
                break;
            }
        }
        
        this.message("after free:--------");
        this.print();
        
        return obj;
    }
    
    
    public void returnObject(Object obj) {
        
        if (this.objects == null)
            return;
        
        this.message("before return:--------");
        this.print();
        PooledObject pooledObject = null;
        Enumeration<PooledObject> enumerate = objects.elements();
        while (enumerate.hasMoreElements()) {
            
            pooledObject = (PooledObject) enumerate.nextElement();
            if (obj == pooledObject.getObject()) {
                
                pooledObject.setBusy(false);
                this.message("return object");
                break;
            }
        }
        this.message("after return:--------");
        this.print();
    }
    
    
    public synchronized void closeObjectPool() {
        
        if (this.objects == null)
            return;
        
        PooledObject pooledObject = null;
        Enumeration<PooledObject> enumerate = objects.elements();
        while (enumerate.hasMoreElements()) {
            
            pooledObject = (PooledObject) enumerate.nextElement();
            this.message(pooledObject.toString());
            if (pooledObject.isBusy()) {
                this.message("wait 5000");
                wait(5000);
            }
        }

        this.objects.clear();
        this.objects = null;
    }
    
    
    private void wait(int millionSeconds) {
        
        try {
            Thread.sleep(millionSeconds);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    
    
    public void print() {
        
        Enumeration<PooledObject> enumerate = objects.elements();
        while (enumerate.hasMoreElements()) {
            
            PooledObject pooledObject = (PooledObject) enumerate.nextElement();
            this.message(pooledObject.toString());
        }
        
        this.message("print end==============================");
    }
    
    
    public void message(String msg) {
        
        if (PRINTABLE) {
            System.out.println(msg);
        }
    }
    
    
    class PooledObject {     
        
        private int index = 0;
        Object objection = null;// 瀵硅薄     
        boolean busy = false// 姝ゅ璞℃槸鍚︽鍦ㄤ嬌鐢ㄧ殑鏍囧織錛岄粯璁ゆ病鏈夋鍦ㄤ嬌鐢?nbsp;    

        
// 鏋勯犲嚱鏁幫紝鏍規嵁涓涓?nbsp;Object 鏋勫憡涓涓?nbsp;PooledObject 瀵硅薄     
        public PooledObject(int index, Object objection) {     

            this.index = index;
            this.objection = objection;
            this.busy = false;
        }     

        // 榪斿洖姝ゅ璞′腑鐨勫璞?nbsp;    
        public Object getObject() {     
            return objection;     
        }     

        // 璁劇疆姝ゅ璞$殑錛屽璞?nbsp;    
        public void setObject(Object objection) {     
            this.objection = objection;     

        }     

        // 鑾峰緱瀵硅薄瀵硅薄鏄惁蹇?nbsp;    
        public boolean isBusy() {     
            return busy;     
        }     

        // 璁劇疆瀵硅薄鐨勫璞℃鍦ㄥ繖     
        public void setBusy(boolean busy) {     
            this.busy = busy;     
        }

        public int getIndex() {
            return index;
        }

        public void setIndex(int index) {
            this.index = index;
        }
        
        @Override
        public String toString() {
            
            return String.format("[PooledObject] index:%d, busy:%b", this.index, this.busy);
        }
    } 
}


class XX {
    
    private int age = 0;
    private String sex = "";
    
    public XX() {
        
    }
    
    public void reset() {
        
        this.age = 0;
        this.sex = "";
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }
}

]]>
centos涓婅繍琛宩nihttp://www.shnenglu.com/misschuer/archive/2015/05/07/210572.html姝ゆ渶鐩告?/dc:creator>姝ゆ渶鐩告?/author>Thu, 07 May 2015 09:14:00 GMThttp://www.shnenglu.com/misschuer/archive/2015/05/07/210572.htmlhttp://www.shnenglu.com/misschuer/comments/210572.htmlhttp://www.shnenglu.com/misschuer/archive/2015/05/07/210572.html#Feedback0http://www.shnenglu.com/misschuer/comments/commentRss/210572.htmlhttp://www.shnenglu.com/misschuer/services/trackbacks/210572.htmlimport java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.StringTokenizer;


public class Test {

    public static native void hello();
        static final String LIBFILENAME = "/home/my/java/libtest.so";

    static {
        //System.loadLibrary(LIBFILENAME);

        try {
            // 鑾峰彇鍒癹ava.library.path  鍙婄郴緇熷彉閲忎腑Path涓殑鍐呭
            String libpath = System.getProperty("java.library.path");
            if (libpath == null || libpath.length() == 0) {
                throw new RuntimeException("java.library.path is null");
            }
            //javaBinPath   jdk鐨刡in鐩綍D:\Program Files\Java\jdk1.6.0_11\bin
            String javaBinPath = null;
            StringTokenizer st = new StringTokenizer(libpath,
                    System.getProperty("path.separator"));
            if (st.hasMoreElements()) {
                javaBinPath = st.nextToken();
            } else {
                throw new RuntimeException("can not split library path:"
                        + libpath);
            }
            // 鎶奷ll鏂囦歡鍐欏叆鍒癹ava.library.path涓dll鏀懼湪ConvertWord2HM鐩稿悓鐩綍涓嬶紝榪欎釜鍙互鏄綘鐨勭被鍚?/span>
            InputStream inputStream = Test.class.getResourceAsStream(
                    LIBFILENAME);
            final File dllFile = new File(LIBFILENAME);
            if (!dllFile.exists()) {
                FileOutputStream outputStream = new FileOutputStream(dllFile);
                byte[] array = new byte[1024];
                int bytesRead = -1;
                while ((bytesRead = inputStream.read(array)) != -1) {
                    outputStream.write(array, 0, bytesRead);
                }
                outputStream.flush();
                outputStream.close();
            }  
            // 鍔ㄦ佸姞杞絛ll
            System.load(dllFile.getPath());
            // 鍦ㄨ櫄鎷熸満鍏抽棴鐨勬椂鍊欏垹闄ll 榪欓噷鐪嬬潃鐢ㄥ惂
            // dllFile.deleteOnExit();
        } catch (Throwable e) {
            throw new RuntimeException("load Convert.dll error!", e);
        }

    }
    public static void main(String[] args) {
        Test.hello();
    }
}


榪欎釜鏂囦歡鏄湪鐩綍/home/my/java涓嬬殑
javac Test.java
javah Test  //鐢熸垚Test.h
鐒跺悗鑷繁鍐橳est.cpp
.java .h .cpp 榪欎簺鏂囦歡鍚嶅瓧涓瀹氳涓鏍?br />
g++ -I$JAVA_HOME/include -I$JAVA_HOME/include/linux -fPIC -shared -o libtest.so Test.cpp  // 杞垚浣犳兂瑕佺殑鏂囦歡 鎴戣繖閲屾槸libtest.so 涔熷彲浠ユ槸libtest.dll, 鐪嬩綘浠g爜璋冪敤浠涔堛?br />java Test 灝卞彲浠ヨ繍琛屼簡
鐢⊿ystem.loadLibrary() 涓鐩村姞杞戒笉浜?鍙兘緗戜笂鎵句簡涓姞杞絣ib鐨勪唬鐮?/div>


]]>
婷婷久久综合九色综合九七| 亚洲AV日韩精品久久久久| 久久久久国产一区二区| 亚洲精品成人网久久久久久| 久久丫精品国产亚洲av不卡| 国产高潮国产高潮久久久91 | 88久久精品无码一区二区毛片 | 99久久精品国产一区二区| 国产亚洲欧美成人久久片| 中文字幕无码久久久| 亚洲综合婷婷久久| 亚洲va久久久噜噜噜久久| 国产精品综合久久第一页| 欧美黑人激情性久久| 日韩欧美亚洲国产精品字幕久久久 | 欧美日韩精品久久久久| 久久国产热这里只有精品| 久久精品国产亚洲精品2020| 久久久久久久久久久久久久 | 国产一级持黄大片99久久| 亚洲精品乱码久久久久久| 久久久久国产精品三级网| 亚洲国产精品热久久| 欧美丰满熟妇BBB久久久| 亚洲乱码精品久久久久..| 亚洲精品久久久www| 亚洲欧美国产日韩综合久久| 国产精品嫩草影院久久| 丁香五月网久久综合| 久久精品aⅴ无码中文字字幕重口| 久久精品国产亚洲AV影院| 色妞色综合久久夜夜| 人人狠狠综合久久亚洲高清| 久久夜色精品国产亚洲av| 国产精品熟女福利久久AV| 香港aa三级久久三级| 久久这里只有精品久久| 久久综合九色综合欧美狠狠| 91精品国产综合久久香蕉| 国产精品美女久久久网AV| 久久久亚洲精品蜜桃臀|