亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? dbconnectiondefaultpool.java

?? Jvie論壇的程序
?? JAVA
?? 第 1 頁(yè) / 共 3 頁(yè)
字號(hào):
     *
     * DbConnectionBroker
     * A servlet-based broker for database connections.
     * Creates and manages a pool of database connections.
     * @version 1.0.11 12/7/99
     * @author Marc A. Mnich
     */
    private class ConnectionPool implements Runnable {
        private Thread runner;

        private Connection[] connPool;
        private int[] connStatus;

        private long[] connLockTime, connCreateDate;
        private String[] connID;
        private String dbDriver, dbServer, dbLogin, dbPassword, logFileString;
        private int currConnections, connLast, minConns, maxConns, maxConnMSec;

        //available: set to false on destroy, checked by getConnection()
        private boolean available=true;

        private PrintWriter log;
        private SQLWarning currSQLWarning;
        private String pid;

        /**
         * Creates a new Connection Broker<br>
         * dbDriver:        JDBC driver. e.g. 'oracle.jdbc.driver.OracleDriver'<br>
         * dbServer:        JDBC connect string. e.g. 'jdbc:oracle:thin:@203.92.21.109:1526:orcl'<br>
         * dbLogin:         Database login name.  e.g. 'Scott'<br>
         * dbPassword:      Database password.    e.g. 'Tiger'<br>
         * minConns:        Minimum number of connections to start with.<br>
         * maxConns:        Maximum number of connections in dynamic pool.<br>
         * logFileString:   Absolute path name for log file. e.g. 'c:\temp\mylog.log' <br>
         * maxConnTime:     Time in days between connection resets. (Reset does a basic cleanup)<br>
         */
        public ConnectionPool (String dbDriver, String dbServer, String dbLogin,
                String dbPassword, int minConns, int maxConns,
                    String logFileString, double maxConnTime) throws IOException
        {
            connPool = new Connection[maxConns];
            connStatus = new int[maxConns];
            connLockTime = new long[maxConns];
            connCreateDate = new long[maxConns];
            connID = new String[maxConns];
            currConnections = minConns;
            this.maxConns = maxConns;
            this.dbDriver = dbDriver;
            this.dbServer = dbServer;
            this.dbLogin = dbLogin;
            this.dbPassword = dbPassword;
            this.logFileString = logFileString;
            maxConnMSec = (int)(maxConnTime * 86400000.0);  //86400 sec/day
            if(maxConnMSec < 30000) {  // Recycle no less than 30 seconds.
                maxConnMSec = 30000;
            }

            try {
                log = new PrintWriter(new FileOutputStream(logFileString),true);
                // Can't open the requested file. Open the default file.
            }
            catch (IOException e1) {
                System.err.println("Warning: DbConnectionDefaultPool could not open \""
                    + logFileString + "\" to write log to. Make sure that your Java " +
                    "process has permission to write to the file and that the directory exists."
                );
                try {
                    log = new PrintWriter(new FileOutputStream("DCB_" +
                        System.currentTimeMillis() + ".log"), true
                    );
                }
                catch (IOException e2) {
                    throw new IOException("Can't open any log file");
                }
            }

            // Write the pid file (used to clean up dead/broken connection)
            SimpleDateFormat formatter
                = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss a zzz");
            java.util.Date nowc = new java.util.Date();
            pid = formatter.format(nowc);

            BufferedWriter pidout = new BufferedWriter(new
                                    FileWriter(logFileString + "pid"));
            pidout.write(pid);
            pidout.close();

            log.println("Starting ConnectionPool:");
            log.println("dbDriver = " + dbDriver);
            log.println("dbServer = " + dbServer);
            log.println("dbLogin = " + dbLogin);
            log.println("log file = " + logFileString);
            log.println("minconnections = " + minConns);
            log.println("maxconnections = " + maxConns);
            log.println("Total refresh interval = " + maxConnTime + " days");
            log.println("-----------------------------------------");


            // Initialize the pool of connections with the mininum connections:
            // Problems creating connections may be caused during reboot when the
            //    servlet is started before the database is ready.  Handle this
            //    by waiting and trying again.  The loop allows 5 minutes for
            //    db reboot.
            boolean connectionsSucceeded=false;
            int dbLoop=20;

            try {
                for(int i=1; i < dbLoop; i++) {
                    try {
                        for(int j=0; j < currConnections; j++) {
                            createConn(j);
                        }
                        connectionsSucceeded=true;
                        break;
                    }
                    catch (SQLException e){
                        log.println("--->Attempt (" + String.valueOf(i) +
                                " of " + String.valueOf(dbLoop) +
                                ") failed to create new connections set at startup: ");
                        log.println("    " + e);
                        log.println("    Will try again in 15 seconds...");
                        try { Thread.sleep(15000); }
                        catch(InterruptedException e1) {}
                    }
                }
                if(!connectionsSucceeded) { // All attempts at connecting to db exhausted
                    log.println("\r\nAll attempts at connecting to Database exhausted");
                    throw new IOException();
                }
            }
            catch (Exception e) {
                e.printStackTrace();
                throw new IOException();
            }

            // Fire up the background housekeeping thread

            runner = new Thread(this);
            runner.start();

        } //End ConnectionPool()


        /**
         * Housekeeping thread.  Runs in the background with low CPU overhead.
         * Connections are checked for warnings and closure and are periodically
         * restarted.
         * This thread is a catchall for corrupted
         * connections and prevents the buildup of open cursors. (Open cursors
         * result when the application fails to close a Statement).
         * This method acts as fault tolerance for bad connection/statement programming.
         */
        public void run() {
            boolean forever = true;
            Statement stmt=null;
            String currCatalog=null;

            while(forever) {
                // Make sure the log file is the one this instance opened
                // If not, clean it up!
                try {
                    BufferedReader in = new BufferedReader(new FileReader(logFileString + "pid"));
                    String curr_pid = in.readLine();
                    if(curr_pid.equals(pid)) {
                        //log.println("They match = " + curr_pid);
                    }
                    else {
                        //log.println("No match = " + curr_pid);
                        log.close();

                         // Close all connections silently - they are definitely dead.
                        for(int i=0; i < currConnections; i++) {
                            try {
                                connPool[i].close();
                            }
                            catch (SQLException e1) {} // ignore
                        }
                        // Returning from the run() method kills the thread
                        return;
                    }
                    in.close();
                }
                catch (IOException e1) {
                    log.println("Can't read the file for pid info: " +
                        logFileString + "pid");
                }

                // Get any Warnings on connections and print to event file
                for(int i=0; i < currConnections; i++) {
                    try {
                        currSQLWarning = connPool[i].getWarnings();
                        if(currSQLWarning != null) {
                            log.println("Warnings on connection " +
                                String.valueOf(i) + " " + currSQLWarning);
                            connPool[i].clearWarnings();
                        }
                    }
                    catch(SQLException e) {
                        log.println("Cannot access Warnings: " + e);
                    }
                }

                for(int i=0; i < currConnections; i++) { // Do for each connection
                    long age = System.currentTimeMillis() - connCreateDate[i];

                    synchronized(connStatus) {
                        if(connStatus[i] > 0) { // In use, catch it next time!
                            continue;
                        }
                        connStatus[i] = 2; // Take offline (2 indicates housekeeping lock)
                    }

                    try {  // Test the connection with createStatement call
                        if(age > maxConnMSec) {  // Force a reset at the max conn time
                            throw new SQLException();
                        }

                        stmt = connPool[i].createStatement();
                        connStatus[i] = 0;  // Connection is O.K.
                        //log.println("Connection confirmed for conn = " +
                        //             String.valueOf(i));

                        // Some DBs return an object even if DB is shut down
                        if(connPool[i].isClosed()) {
                            throw new SQLException();
                        }
                        // Connection has a problem, restart it
                    }
                    catch(SQLException e) {
                        try {
                            log.println(new Date().toString() +
                                " ***** Recycling connection " +
                                String.valueOf(i) + ":"
                            );

                            connPool[i].close();
                            createConn(i);
                        }
                        catch(SQLException e1) {
                            log.println("Failed: " + e1);
                            connStatus[i] = 0;  // Can't open, try again next time
                        }
                    }
                    finally {
                        try {
                            if(stmt != null) {
                                stmt.close();
                            }
                        }
                        catch(SQLException e1){};
                    }
                }

                try {
                    Thread.sleep(20000);
                }  // Wait 20 seconds for next cycle
                catch(InterruptedException e) {
                    // Returning from the run method sets the internal
                    // flag referenced by Thread.isAlive() to false.
                    // This is required because we don't use stop() to
                    // shutdown this thread.
                    return;
                }
            }
        } // End run

        /**
         * This method hands out the connections in round-robin order.
         * This prevents a faulty connection from locking
         * up an application entirely.  A browser 'refresh' will
         * get the next connection while the faulty
         * connection is cleaned up by the housekeeping thread.
         *
         * If the min number of threads are ever exhausted, new
         * threads are added up the the max thread count.
         * Finally, if all threads are in use, this method waits
         * 2 seconds and tries again, up to ten times.  After that, it
         * returns a null.
         */
        public Connection getConnection() {

            Connection conn=null;

            if(available){
                boolean gotOne = false;

                for(int outerloop=1; outerloop<=10; outerloop++) {

                    try  {
                        int loop=0;
                        int roundRobin = connLast + 1;
                        if(roundRobin >= currConnections) roundRobin=0;

                        do {
                            synchronized(connStatus) {
                                if((connStatus[roundRobin] < 1) &&
                                                    (! connPool[roundRobin].isClosed()))
                                {
                                    conn = connPool[roundRobin];
                                    connStatus[roundRobin]=1;
                                    connLockTime[roundRobin] =
                                                            System.currentTimeMillis();
                                    connLast = roundRobin;
                                    gotOne = true;
                                    break;
                                }
                                else {
                                    loop++;
                                    roundRobin++;
                                    if(roundRobin >= currConnections) roundRobin=0;
                                }
                            }
                        }
                        while((gotOne==false)&&(loop < currConnections));
                    }
                    catch (SQLException e1) {}

                    if(gotOne) {
                        break;
                    }
                    else {
                        synchronized(this) {  // Add new connections to the pool
                            if(currConnections < maxConns) {
                                try {
                                    createConn(currConnections);
                                                    currConnections++;
                                }
                                catch(SQLException e) {
                                    log.println("Unable to create new connection: " + e);
                                }
                            }
                        }

                        try { Thread.sleep(2000); }
                        catch(InterruptedException e) {}
                        log.println("-----> Connections Exhausted!  Will wait and try " +
                            "again in loop " +
                            String.valueOf(outerloop));
                    }
                } // End of try 10 times loop

            }
            else {
                log.println("Unsuccessful getConnection() request during destroy()");
            } // End if(available)

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文在线一区二区| 亚洲视频免费看| 日韩美女精品在线| 综合色天天鬼久久鬼色| 欧美xxxxx裸体时装秀| 亚洲裸体在线观看| 日韩av中文在线观看| 成人福利在线看| 精品精品国产高清一毛片一天堂| 亚洲免费观看高清在线观看| 国内外精品视频| 欧美日韩成人综合| 亚洲丝袜制服诱惑| 成人高清视频在线| 久久久久久黄色| 捆绑紧缚一区二区三区视频| 欧美日韩精品一区二区天天拍小说 | 午夜影视日本亚洲欧洲精品| 成人app网站| 国产亚洲人成网站| 久久99久久久久| 欧美日韩一区二区三区四区| 欧美一区二区三区在| 亚洲国产成人私人影院tom| 日韩黄色免费网站| 欧美日韩aaa| 午夜精品在线看| 欧美三级电影在线观看| 日韩毛片视频在线看| 成人免费视频一区二区| 国产欧美1区2区3区| 国产一区二区主播在线| 久久久久久久综合日本| 国产高清在线精品| 中文幕一区二区三区久久蜜桃| 国产精品一区二区在线看| 久久先锋影音av鲁色资源| 国产一区高清在线| 国产农村妇女毛片精品久久麻豆 | 国产一区二区视频在线播放| 精品欧美一区二区三区精品久久| 久久爱另类一区二区小说| 欧美成va人片在线观看| 国产精品原创巨作av| 日本一区二区三区电影| 91色在线porny| 夜色激情一区二区| 日韩一区二区三区视频在线观看| 麻豆91免费看| 日本一二三四高清不卡| 91伊人久久大香线蕉| 亚洲高清视频中文字幕| 日韩一区二区免费在线电影| 经典三级一区二区| 国产精品免费视频一区| 欧美性欧美巨大黑白大战| 蜜臀久久久99精品久久久久久| 久久久久久久久岛国免费| 91在线视频18| 麻豆91在线播放免费| 国产精品久久久久影院| 欧美日韩你懂得| 国产最新精品精品你懂的| 亚洲柠檬福利资源导航| 91.麻豆视频| www.在线成人| 日韩电影免费一区| 国产精品女上位| 欧美一区二区三区在| 成人aa视频在线观看| 奇米亚洲午夜久久精品| 国产精品美女久久久久av爽李琼| 欧美日韩国产一级片| 国产成人在线视频播放| 亚洲成人av电影| 国产精品久久久久久久久晋中 | 91麻豆精品国产自产在线观看一区| 国内精品伊人久久久久av影院 | 亚洲精品免费在线播放| 日韩亚洲欧美一区二区三区| 97精品视频在线观看自产线路二| 麻豆国产精品视频| 亚洲精品视频免费看| 久久综合九色综合欧美98| 欧美羞羞免费网站| 99久久精品国产一区| 极品瑜伽女神91| 偷拍与自拍一区| 亚洲精品你懂的| 国产精品网曝门| 欧美精品一区二区高清在线观看| 在线一区二区观看| 99精品视频在线免费观看| 国产一区二区三区在线观看免费视频| 亚洲sss视频在线视频| 中文字幕字幕中文在线中不卡视频| 精品国产伦理网| 91精品国产免费| 欧美日韩在线亚洲一区蜜芽| 91丝袜高跟美女视频| 春色校园综合激情亚洲| 久久99精品久久久| 麻豆成人综合网| 精一区二区三区| 美国三级日本三级久久99| 日韩国产欧美视频| 亚洲高清视频的网址| 亚洲国产一区二区在线播放| 玉米视频成人免费看| 亚洲欧洲成人精品av97| 国产精品水嫩水嫩| 中文久久乱码一区二区| 国产精品女主播在线观看| 欧美极品少妇xxxxⅹ高跟鞋| 久久九九久精品国产免费直播| 久久婷婷国产综合精品青草| 久久综合五月天婷婷伊人| 久久一区二区视频| 国产午夜亚洲精品羞羞网站| 中文字幕av在线一区二区三区| 国产日韩成人精品| 亚洲欧洲日韩av| 一区二区三区免费| 三级成人在线视频| 蜜臀国产一区二区三区在线播放| 麻豆成人免费电影| 国产成人av自拍| 91亚洲永久精品| 欧美日韩一级二级| 日韩三级视频在线观看| 久久久精品蜜桃| 亚洲欧洲日产国产综合网| 亚洲福利电影网| 奇米综合一区二区三区精品视频| 久久国产精品99久久人人澡| 国产精品99久久久久久有的能看 | 日韩精品中文字幕在线一区| 久久看人人爽人人| 亚洲欧美日韩在线播放| 丝袜美腿亚洲一区| 精品在线一区二区| 成人h动漫精品一区二| 色999日韩国产欧美一区二区| 欧美日韩在线一区二区| 久久久精品免费免费| 亚洲精品网站在线观看| 久久爱www久久做| 91免费观看在线| 日韩三级伦理片妻子的秘密按摩| 国产精品亲子乱子伦xxxx裸| 亚洲二区视频在线| 国产成人丝袜美腿| 欧美日韩精品一区二区三区四区| 久久精品视频一区二区三区| 亚洲已满18点击进入久久| 精品一区二区三区视频| 日本高清不卡视频| 久久女同互慰一区二区三区| 依依成人综合视频| 福利一区二区在线| 欧美日本在线一区| 中文一区二区在线观看 | 亚洲午夜私人影院| 国产剧情一区二区三区| 欧美视频自拍偷拍| 国产精品水嫩水嫩| 久久99国产精品麻豆| 欧美性大战久久久| 亚洲国产成人私人影院tom| 青青草精品视频| 欧亚一区二区三区| 国产精品免费网站在线观看| 极品销魂美女一区二区三区| 欧美系列日韩一区| 国产精品国产三级国产aⅴ入口| 久久精品国产一区二区三 | 久久久久久久久久电影| 五月天丁香久久| 在线观看一区二区视频| 国产精品毛片久久久久久久| 免费观看在线综合色| 欧美最猛黑人xxxxx猛交| 中文字幕国产一区二区| 九九精品视频在线看| 欧美日韩成人一区二区| 亚洲男同性恋视频| 97久久久精品综合88久久| 久久精品亚洲麻豆av一区二区| 日韩av电影免费观看高清完整版 | 国产午夜久久久久| 国产揄拍国内精品对白| 日韩视频永久免费| 日韩av电影免费观看高清完整版 | 欧美大片在线观看一区二区| 天天综合网天天综合色| 精品视频在线免费看| 亚洲欧美国产三级| 日本二三区不卡| 一区二区三区高清在线| 欧美在线短视频|