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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? connectionpool.java

?? 這個雖然非常簡單
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
// place this in a package
//package  com.webdoyen.database;

import  java.sql.*;
import  java.util.*;
import  java.util.Timer;
import  java.util.TimerTask;


/*
 JAVADOC ME AND READ THE JAVADOCS - IT WILL BE VERY EASY TO UNDERSTAND THEN

 Here's how:
   javadoc -d docs ConnectionPool.java

 where "docs" is a directory to place the documentation into
*/


/**
 * <h2>Creates and handles a pool of database connections.</h2>
 *                                                                         <P>
 * Methods allow for getting a connection from the pool                    <BR>
 * and returning a connection to the pool.
 *                                                                         <P>
 * The pool will dynamically grow as needed, and over time                 <BR>
 * reduce itself back to its original size if some of the                  <BR>
 * connections aren't being used.                                          <P>
 *
 * Jeff Patterson (jeff@webdoyen.com)  - <a target=_blank href="http://www.webdoyen.com">www.webdoyen.com</a> - (c) 2001  <P>
 * 
 * <small><B>This code is distributed under the GNU GENERAL PUBLIC LICENSE - you MAY USE OR MODIFY IT as you like,    
 * but CANNOT charge money for this single piece of code.  You MAY USE this code WITHIN a piece of software
 * that you charge money for.</B></small>
 * <P><code>
 * <a href="#COMPLEX">See example using complex constructor</a><BR>
 * <a href="#SIMPLE">See example using simple constructor</a>
 * </code><P>
 * <table bgcolor="#DDDDDD" border="1" cellpadding="4" cellspacing="0"><tr><td>
 * <a name="COMPLEX"><B>example using complex constructor:</B></a>
 * <pre><code>
 * ConnectionPool pool = null;
 * String dbURL = "jdbcurl_here";
 * String dbUserName = "someusername";
 * String dbPassword = "somepassword";
 * String dbDriver = "jdbc.driver";
 * try 
 * {
 *      // open a pool of 10 connections - when I run low, open 5 more
 *      // check my pool's health every 2 minutes, and keep "extra" idle
 *      // connections alive for 3 minutes before closing them down
 *      pool = new ConnectionPool( dbURL , dbUserName , dbPassword, dbDriver, 10, 5, 2, 3 );
 * } 
 * catch(SQLException e)  // thrown if problems building connections to database
 * {
 *     System.out.println( e.getMessage() );
 * }
 * catch(ClassNotFoundException cnf)  // thrown if db class driver not found in classpath
 * {
 *     System.out.println( cnf.getMessage() );
 * }
 *
 * // now that the pool is running, we can use it's connections...
 *
 * Connection con = null;
 * try {
 *     con = pool.getConnection();    // get a connection from the pool
 *     // use the connection...
 *     // ...
 *     // done using the connection
 *     pool.returnConnection( con );  // return the connection to the pool
 * } 
 * catch(SQLException e)  // thrown if problems building connections to database
 * {
 *     System.out.println( e.getMessage() );
 * }
 * </code></pre>
 * </td></tr></table>
 * <P>
 * <table bgcolor="#DDDDDD" border="1" cellpadding="4" cellspacing="0"><tr><td>
 * <a name="#SIMPLE"><B>example using default/simple constructor:</B></a>
 * <code><pre>
 * ConnectionPool pool = new ConnectionPool();                     // construct an empty pool
 * try
 * {
 *      pool.setURL("jdbc:mysql://localhost:3306/store_product");  // MySQL database on local machine
 *      pool.setDriverClassName("org.gjt.mm.mysql.Driver");        // DB driver - must be in classpath
 *      pool.start();                                              // Start the pool
 *      Connection con = pool.getConnection("Test Program");       // get a connection and identify ourselves
 *      // here is where we use the pool
 *      pool.returnConnection( con );                              // return a connection
 *      System.out.println( pool.getReport() );                    // let's see a report of the pool
 *  }
 *  catch(SQLException e)  // might be thrown by start() or getConnection()
 *  {
 *      System.out.println( e.getMessage() );
 *  }
 *  catch(ClassNotFoundException cnf)  // might be thrown by setDriverClassName()
 *  {
 *      System.out.println( cnf.getMessage() );
 *  }
 * </pre></code>
 * </td></tr></table>
 *
 * @author Jeff Patterson (<a href="mailto:jeff@webdoyen.com">jeff@webdoyen.com</a>)  - www.webdoyen.com - (c) 2001
 */
public class ConnectionPool 
{
    // CONSTANTS
    private static final String NEWLINE = System.getProperty( "line.separator" ); // platform dependant newline for our report

    // switch this to true if you want to use it in production environment
    // it is used by the exerciseConnection() method to determine how much
    // of a workout to give a connection
    private static final boolean PRODUCTION = false;

    private static final boolean DEBUG = false;        // I used this when programming this originally
    
    // MEMBERS
    private Hashtable connections = null;    // this will hold our connections
    private int increment = 1;               // how many new cons to open if the pool is all used up
    private int iterationTime = 10;          // number of minutes to wait before checking integrity
    private String dbURL, user, password;    // JDBC settings
    private int initialConnections = 1;      // initial connections to open
    private int minutesIdle = 5;             // any connection over initialConnections that has been idle for this long or longer is closed
    private Timer timer = null;              // the Timer that will keep track of connection integrity, etc.
    private boolean classDriverSet = false;  // has the class driver been set for this pool?


    /**
     * Default constructor - there is some setup required
     * <P>See the <code>start()</code> method to understand how to set up and start the pool<BR>
     * You may also want to look at the <a href="#SIMPLE">default constructor example</a> to see a VERY simple example<P>
     * @see #start
     */
    public ConnectionPool()
    {
    }

    /**
     * Make a connection pool based on the parameters<P>
     * By using this complex constructor, you will skip having to go through the
	 * individual steps associated with the default/empty constructor (<code>ConnectionPool()</code>)
	 * <P>
     * This connection pool will automatically start - you do not need to issue the <code>start()</code> command
     * <P>
     * @param  dbURL JDBC url of the DB
     * @param  user database username
     * @param  password database password
     * @param  driverClassName JDBC Driver Class Name
     * @param  initialConnections number of connections to open initially.  
	 *         The pool will never have fewer than this many connections established to the DB.
     * @param  increment number of connections to open if you try and get a connection from the pool but
     *         there are none available.  These "extra" connections will be closed over time if they remain idle.
     * @param  iterationTime time (in munites) between connection integrity checks.
     * @param  timeInMinutes time (in munites) to keep an idle connection alive before closing it
     * @see    #ConnectionPool()
     */
    public ConnectionPool (String dbURL, String user, String password, String driverClassName, int initialConnections, int increment, int iterationTime,  int minutesIdle) throws SQLException, ClassNotFoundException
    {
        // Load the specified driver class
        setDriverClassName(driverClassName);
        setURL(dbURL);
        setUser(user);
        setPassword(password);
        setIncrementCount(increment);
        setInitialConnections(initialConnections);
        setHealthCheckIterationTime(iterationTime);
        setMinutesIdle( minutesIdle );
        start();
    }

    /**
     * Gets a connection from the pool - you MUST return it
     * <P>You must return it via <code>returnConnection()</code> when you're done with it.  Failure to do so
     * will cause this connection to be permanently "checked out" of the pool, and never again usable.
     * <P>
     * @throws SQLException if a connection is unhealthy and we have to make a new one, getConnection throws
     *  an error if the new connection isn't made successfully
     * @see #returnConnection
     * @see #getConnection(String)
     */
    public Connection getConnection () throws SQLException
    {
        return  (getConnection(null));        // polymorphic getConnection
    }

    /**
     * Gets a connection from the pool - you MUST return it
     * <P>You must return it via <code>returnConnection()</code> when you're done with it.  Failure to do so
     * will cause this connection to be permanently "checked out" of the pool, and never again usable.
     * <P>
     * @param appId identifer of application.  Used in the report created by <code>getReport()</code>
     * @throws SQLException if a connection is unhealthy and we have to make a new one, getConnection throws an error if the new connection isn't made successfully
     * @see #returnConnection
     * @see #getConnection()
     * @see #getReport
     */
    public Connection getConnection (String appId) throws SQLException
    {
        // polymorphic getConnection
        Connection con = null;
        Enumeration cons = connections.keys();
        synchronized (connections) {
            while (cons.hasMoreElements()) 
            {
                con = (Connection)cons.nextElement();
                //Boolean b = new Boolean( ( (ConData)connections.get(con) ).inUse );
                //if (b == Boolean.FALSE) {
                if (((ConData)connections.get(con)).inUse == false) 
                {
                    // So we found an unused connection.
                    // Test its integrity with a quick setAutoCommit(true) call.
                    // For production use, more testing could be performed, such as a simple query.
                    try 
                    {
                        con.setAutoCommit(true);
                    } 
                    catch (SQLException e) 
                    {
                        // Problem with the connection, replace it.
                        con = DriverManager.getConnection(dbURL, user, password);
                    }
                    // Update the Hashtable to show this one's taken
                    connections.put(con, new ConData(true, appId));
                    // Return the connection
                    return  con;
                }
            }
        }
        // If we get here, there were no free connections - we've got to make more.
        for (int i = 0; i < increment; i++) // make however many we've decided on
            connections.put(DriverManager.getConnection(dbURL, user, password), new ConData());

        // Recurse to get one of the new connections.
        return  getConnection(appId);
    }

    /** This will return a connection to the pool and free it up for something else 
     * @param connection the connection from the pool that you're done using and ready to put back in the pool
     * @return <code>true</code> if the connection is returned without problems, else <code>false</code> (should never happen)
     * @see #getConnection
     */
    public boolean returnConnection (Connection connection)
    {
        boolean returnVal = false;
        Connection con;
        Enumeration cons = connections.keys();
        while (cons.hasMoreElements()) 
        {
            con = (Connection)cons.nextElement();
            if (con == connection) 
            {
                connections.put(con, new ConData());
                returnVal = true;
                break;
            }
        }
        return  (returnVal);
    }

    /** Starts the pool<P>
     *  You are only required to issue the <code>start()</code> method if you have
     *  used the default/empty constructor (<code>ConnectionPool()</code>) to build your pool.
     *  The complex constructor automatically starts the pool.
     *  <P>
     *  Before starting the pool, you <B>must call</B> the following (in no particular order):
     *  <code>
     *  <ul>
     *  <li>setDriverClassName()
     *  <li>setURL()
     *  </ul>
     *  </code>
     *  <P>You will <B>almost certainly have to call</B> the following:
     *  <code>
     *  <ul>
     *  <li>setUser()
     *  <li>setPassword()
     *  </ul>
     *  </code>
     *  <P>In addition, you <B>may call</B> any or all of these:
     *  <ul>
     *  <li><code>setIncrementCount()</code>            <small><I>   (default is 1)</I></small>
     *  <li><code>setInitialConnections()</code>   <small><I>        (default is 1)</I></small>
     *  <li><code>setHealthCheckIterationTime()</code>   <small><I>  (default is 10)</I></small>
     *  <li><code>setMinutesIdle()</code>   <small><I>               (default is 5)</I></small>
     *  </ul>
     *  <P>
     *  @see #ConnectionPool()
     *  @see #setDriverClassName
     *  @see #setURL
     *  @see #setUser
     *  @see #setPassword
     *  @see #setIncrementCount
     *  @see #setInitialConnections
     *  @see #setHealthCheckIterationTime
     *  @see #setMinutesIdle
     */
    public void start() throws SQLException
    {
        if (this.connections != null) return; // we have already started the pool, so let's get out of here!

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲曰韩产成在线| 国产精品一区免费在线观看| 99精品视频在线免费观看| 日本一区二区免费在线| 国产成人综合网| 国产精品萝li| av成人免费在线观看| 亚洲天天做日日做天天谢日日欢| 成人一二三区视频| 一区二区三区在线观看欧美| 在线观看日韩高清av| 亚洲成a人片综合在线| 欧美一级片在线看| 亚洲欧美另类综合偷拍| 国产精品传媒在线| 亚洲国产精品二十页| 久久久久国产精品麻豆ai换脸| 亚洲第一福利视频在线| 久久亚洲二区三区| 国产aⅴ综合色| 一区二区三区欧美| 7777精品伊人久久久大香线蕉经典版下载 | 国精产品一区一区三区mba视频 | 日韩精品一区二区三区蜜臀 | 国内精品不卡在线| 国产精品久久久久久久午夜片 | 日韩一区二区在线看| 国产精品美女久久久久久久久| 国内偷窥港台综合视频在线播放| 中文字幕av一区二区三区| 欧美色图在线观看| 国产裸体歌舞团一区二区| 亚洲精品视频一区| 精品久久人人做人人爽| 99精品视频一区| 美女网站视频久久| 日韩理论片在线| 26uuu久久天堂性欧美| 91日韩精品一区| 激情小说欧美图片| 一区二区三区精品视频在线| 欧美精品 日韩| 不卡一区在线观看| 麻豆精品在线播放| 一区二区三区久久久| 久久综合资源网| 欧美日韩在线免费视频| 国产麻豆精品95视频| 日韩av一区二区在线影视| 亚洲男人的天堂网| 久久精品网站免费观看| 色综合久久久久综合| 在线电影院国产精品| 国产一区二区三区免费在线观看 | 亚洲精品乱码久久久久久| 欧美亚洲日本一区| 高清视频一区二区| 毛片一区二区三区| 丝瓜av网站精品一区二区| 成人亚洲精品久久久久软件| 精品国产91亚洲一区二区三区婷婷| 成人一区二区在线观看| 久久激五月天综合精品| 午夜天堂影视香蕉久久| 一区二区三区免费网站| 国产精品第四页| 欧美日韩精品一区二区| 91色在线porny| 亚洲久草在线视频| 7777精品伊人久久久大香线蕉| 欧美日韩午夜精品| 91激情在线视频| 91美女在线观看| 成人黄色777网| 岛国一区二区在线观看| 国产在线国偷精品产拍免费yy| 麻豆精品在线看| 裸体健美xxxx欧美裸体表演| 日本在线不卡一区| 青娱乐精品视频在线| 日韩成人dvd| 久久精品99国产精品日本| 久久超碰97中文字幕| 精品一区二区三区在线观看| 精品在线免费视频| 国产高清亚洲一区| 成人一区二区三区视频在线观看| 国产成人啪免费观看软件| 成人毛片在线观看| aaa国产一区| 色综合久久中文综合久久97| 欧美色综合天天久久综合精品| 青青国产91久久久久久| 国产亚洲美州欧州综合国| 国产精品久久久一本精品| 国产免费观看久久| 中文字幕在线一区| 国产精品你懂的在线欣赏| 亚洲欧洲av另类| 亚洲影院理伦片| 日本在线不卡一区| 国产一区二区免费视频| 国产精品1区二区.| 色婷婷久久一区二区三区麻豆| 欧美视频一区在线| 5月丁香婷婷综合| 国产日韩欧美激情| 亚洲一二三四久久| 久久99精品久久久久久动态图 | 久久免费精品国产久精品久久久久| 久久亚洲一区二区三区明星换脸| 中文字幕中文字幕中文字幕亚洲无线 | 日韩精品成人一区二区在线| 国产日韩成人精品| 亚洲激情图片qvod| 看片的网站亚洲| 不卡视频在线观看| 欧美丰满少妇xxxbbb| 国产午夜精品福利| 亚洲第一主播视频| 国产+成+人+亚洲欧洲自线| 在线看国产一区| 久久嫩草精品久久久精品| 亚洲欧洲综合另类在线| 麻豆精品一区二区| 色欧美乱欧美15图片| 日韩欧美一二三四区| 中文字幕在线一区| 久久99国产精品麻豆| 色噜噜久久综合| 久久久五月婷婷| 日韩一区欧美二区| 成人av免费在线| 欧美成人猛片aaaaaaa| 亚洲最色的网站| 国产成人av电影| 精品少妇一区二区三区视频免付费| 亚洲久草在线视频| 从欧美一区二区三区| 欧美成人精品高清在线播放| 一区二区三区91| 99精品国产91久久久久久| 久久免费偷拍视频| 麻豆成人久久精品二区三区红 | 欧美视频在线观看一区二区| 日本一区二区免费在线观看视频 | 欧美日韩亚洲丝袜制服| 国产精品拍天天在线| 国产专区综合网| 日韩午夜激情av| 亚洲福利电影网| 欧美午夜精品一区| 亚洲免费在线播放| 成人午夜av电影| 久久久精品国产99久久精品芒果| 免费高清在线视频一区·| 欧美日韩国产在线播放网站| 亚洲男人电影天堂| 色综合久久88色综合天天免费| 国产精品欧美久久久久一区二区| 精品午夜一区二区三区在线观看| 欧美人xxxx| 日本不卡一区二区三区| 91麻豆精品国产91久久久久久| 亚洲专区一二三| 精品视频免费在线| 偷拍亚洲欧洲综合| 在线播放/欧美激情| 日日夜夜免费精品视频| 51午夜精品国产| 日韩不卡在线观看日韩不卡视频| 91精品麻豆日日躁夜夜躁| 五月天久久比比资源色| 欧美日本免费一区二区三区| 天天综合网 天天综合色| 在线成人免费观看| 久久精品99国产精品日本| 久久综合给合久久狠狠狠97色69| 精品一区二区av| 国产婷婷色一区二区三区四区 | 国产精品久久久久影院亚瑟| 99国产精品久| 亚洲愉拍自拍另类高清精品| 欧美日韩激情在线| 精品一区二区日韩| 中文文精品字幕一区二区| 91在线观看视频| 亚洲国产婷婷综合在线精品| 欧美一卡2卡3卡4卡| 国产一区二区三区精品欧美日韩一区二区三区 | 精品国产区一区| 国产91精品一区二区麻豆亚洲| 亚洲欧美在线另类| 欧洲av一区二区嗯嗯嗯啊| 老司机免费视频一区二区| 日本一区二区三区dvd视频在线| 色婷婷综合中文久久一本| 午夜伦欧美伦电影理论片| 久久久久久久久久久久电影| 成人国产一区二区三区精品|