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

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

?? connectionpool.java

?? bbs頁面聊天系統
?? JAVA
字號:
package sjservlets;

import java.sql.*;
import java.util.*;

/** A class for preallocating, recycling, and managing
 *  JDBC connections.
 *
 *  © 2002 Song Jing; may be freely used or adapted.
 */

public class ConnectionPool implements Runnable {
  private String driver, url, username, password;
  private int maxConnections;
  private boolean waitIfBusy;
  private Vector availableConnections, busyConnections;
  private boolean connectionPending = false;

  public ConnectionPool(String driver, String url,
                        String username, String password,
                        int initialConnections,
                        int maxConnections,
                        boolean waitIfBusy)
      throws SQLException {
    this.driver = driver;
    this.url = url;
    this.username = username;
    this.password = password;
    this.maxConnections = maxConnections;
    this.waitIfBusy = waitIfBusy;
    if (initialConnections > maxConnections) {
      initialConnections = maxConnections;
    }
    availableConnections = new Vector(initialConnections);
    busyConnections = new Vector();
    for(int i=0; i<initialConnections; i++) {
      availableConnections.addElement(makeNewConnection());
    }
  }
  
  public synchronized Connection getConnection()
      throws SQLException {
    if (!availableConnections.isEmpty()) {
      Connection existingConnection =
        (Connection)availableConnections.lastElement();
      int lastIndex = availableConnections.size() - 1;
      availableConnections.removeElementAt(lastIndex);
      // If connection on available list is closed (e.g.,
      // it timed out), then remove it from available list
      // and repeat the process of obtaining a connection.
      // Also wake up threads that were waiting for a
      // connection because maxConnection limit was reached.
      if (existingConnection.isClosed()) {
        notifyAll(); // Freed up a spot for anybody waiting
        return(getConnection());
      } else {
        busyConnections.addElement(existingConnection);
        return(existingConnection);
      }
    } else {
      
      // Three possible cases:
      // 1) You haven't reached maxConnections limit. So
      //    establish one in the background if there isn't
      //    already one pending, then wait for
      //    the next available connection (whether or not
      //    it was the newly established one).
      // 2) You reached maxConnections limit and waitIfBusy
      //    flag is false. Throw SQLException in such a case.
      // 3) You reached maxConnections limit and waitIfBusy
      //    flag is true. Then do the same thing as in second
      //    part of step 1: wait for next available connection.
      
      if ((totalConnections() < maxConnections) &&
          !connectionPending) {
        makeBackgroundConnection();
      } else if (!waitIfBusy) {
        throw new SQLException("Connection limit reached");
      }
      // Wait for either a new connection to be established
      // (if you called makeBackgroundConnection) or for
      // an existing connection to be freed up.
      try {
        wait();
      } catch(InterruptedException ie) {}
      // Someone freed up a connection, so try again.
      return(getConnection());
    }
  }

  // You can't just make a new connection in the foreground
  // when none are available, since this can take several
  // seconds with a slow network connection. Instead,
  // start a thread that establishes a new connection,
  // then wait. You get woken up either when the new connection
  // is established or if someone finishes with an existing
  // connection.

  private void makeBackgroundConnection() {
    connectionPending = true;
    try {
      Thread connectThread = new Thread(this);
      connectThread.start();
    } catch(OutOfMemoryError oome) {
      // Give up on new connection
    }
  }

  public void run() {
    try {
      Connection connection = makeNewConnection();
      synchronized(this) {
        availableConnections.addElement(connection);
        connectionPending = false;
        notifyAll();
      }
    } catch(Exception e) { // SQLException or OutOfMemory
      // Give up on new connection and wait for existing one
      // to free up.
    }
  }

  // This explicitly makes a new connection. Called in
  // the foreground when initializing the ConnectionPool,
  // and called in the background when running.
  
  private Connection makeNewConnection()
      throws SQLException {
    try {
      // Load database driver if not already loaded
      Class.forName(driver);
      // Establish network connection to database
      Connection connection =
        DriverManager.getConnection(url, username, password);
      return(connection);
    } catch(ClassNotFoundException cnfe) {
      // Simplify try/catch blocks of people using this by
      // throwing only one exception type.
      throw new SQLException("Can't find class for driver: " +
                             driver);
    }
  }

  public synchronized void free(Connection connection) {
    busyConnections.removeElement(connection);
    availableConnections.addElement(connection);
    // Wake up threads that are waiting for a connection
    notifyAll(); 
  }
    
  public synchronized int totalConnections() {
    return(availableConnections.size() +
           busyConnections.size());
  }

  /** Close all the connections. Use with caution:
   *  be sure no connections are in use before
   *  calling. Note that you are not <I>required</I> to
   *  call this when done with a ConnectionPool, since
   *  connections are guaranteed to be closed when
   *  garbage collected. But this method gives more control
   *  regarding when the connections are closed.
   */

  public synchronized void closeAllConnections() {
    closeConnections(availableConnections);
    availableConnections = new Vector();
    closeConnections(busyConnections);
    busyConnections = new Vector();
  }

  private void closeConnections(Vector connections) {
    try {
      for(int i=0; i<connections.size(); i++) {
        Connection connection =
          (Connection)connections.elementAt(i);
        if (!connection.isClosed()) {
          connection.close();
        }
      }
    } catch(SQLException sqle) {
      // Ignore errors; garbage collect anyhow
    }
  }
  
  public synchronized String toString() {
    String info =
      "ConnectionPool(" + url + "," + username + ")" +
      ", available=" + availableConnections.size() +
      ", busy=" + busyConnections.size() +
      ", max=" + maxConnections;
    return(info);
  }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
青青草原综合久久大伊人精品优势| 天天影视色香欲综合网老头| 亚洲精品日韩专区silk| 午夜电影网一区| 成人av集中营| 精品少妇一区二区三区免费观看| 亚洲激情网站免费观看| 国产一区二区女| 日韩一级完整毛片| 亚洲一区中文在线| eeuss鲁片一区二区三区在线观看| 日韩欧美一级在线播放| 亚洲国产视频直播| 91免费版在线看| 亚洲四区在线观看| 高清日韩电视剧大全免费| 欧美一区二区三区爱爱| 亚洲一区二三区| 在线视频一区二区三区| 国产精品久久久久久妇女6080| 免费人成在线不卡| 欧美日韩色综合| 亚洲六月丁香色婷婷综合久久 | 国产精品电影院| 国产精品一品视频| 成人性色生活片| 同产精品九九九| 国产精品色哟哟| 欧美电视剧免费观看| 欧美在线free| 不卡一区在线观看| 国内精品久久久久影院薰衣草 | 亚洲大片免费看| 国产91高潮流白浆在线麻豆 | 国产成人免费视频一区| 久久亚洲精品小早川怜子| 精品亚洲国产成人av制服丝袜| 日韩一卡二卡三卡四卡| 免费视频一区二区| 欧美乱妇15p| 婷婷丁香久久五月婷婷| 777奇米四色成人影色区| 首页国产欧美久久| 91精品婷婷国产综合久久| 欧美精品在线一区二区三区| 91蜜桃免费观看视频| 久久99热这里只有精品| 久久美女高清视频| 国产高清不卡一区| 午夜影视日本亚洲欧洲精品| 中文字幕一区二区三区四区不卡| 欧美日韩亚洲另类| 欧美亚洲禁片免费| 欧美韩国一区二区| 蜜桃av噜噜一区二区三区小说| 91精品国产综合久久久久久久久久 | 一区二区三区精品在线| xnxx国产精品| 亚洲国产日韩a在线播放性色| 欧美老年两性高潮| 色婷婷综合久久久久中文一区二区 | 久久91精品国产91久久小草| 国产精品美女久久福利网站| 久久久精品一品道一区| 国产精品视频你懂的| 国产精品久久久久婷婷| 一区二区三区在线视频观看| 丝袜美腿成人在线| 久久精品国产一区二区| 洋洋成人永久网站入口| 国内一区二区视频| 91精品免费在线| 麻豆精品在线看| 久久一区二区视频| 99免费精品在线观看| 国产欧美日韩综合| 色哟哟在线观看一区二区三区| 久久久久久久久久看片| 日本精品一区二区三区高清| 午夜视频一区二区三区| 国产精品高潮久久久久无| 色婷婷av一区| 国产成人精品免费视频网站| 中文字幕av一区二区三区免费看| 精品视频123区在线观看| 久久国产人妖系列| 亚洲高清在线视频| 欧美日韩亚州综合| 成人美女视频在线看| 午夜久久久久久| 国产精品三级av| 555www色欧美视频| 99视频精品免费视频| 秋霞av亚洲一区二区三| 一区二区在线看| 亚洲精品一区二区三区精华液| 欧美性大战久久| 国产成人午夜视频| 在线免费视频一区二区| 国产网站一区二区三区| 色综合网站在线| 亚洲人吸女人奶水| 在线观看视频一区二区| 国产午夜亚洲精品理论片色戒| 免费av网站大全久久| 欧美精品黑人性xxxx| 免费高清视频精品| 国产午夜亚洲精品不卡| 国产在线播放一区三区四| 国产精品三级电影| 国产91在线|亚洲| 一区二区三区不卡在线观看| 欧美精品久久99| 91麻豆国产自产在线观看| 国产一区二区三区在线看麻豆| 天天操天天干天天综合网| 18涩涩午夜精品.www| 亚洲视频在线一区二区| 久久精品人人做| 欧美国产成人在线| 久久蜜臀中文字幕| 中文字幕的久久| 国产亚洲人成网站| 亚洲国产成人在线| 久久免费精品国产久精品久久久久| 日韩一级免费一区| 日韩一区二区电影| 久久久久免费观看| 久久久久久久久99精品| 国产视频视频一区| 国产日韩在线不卡| 日韩一区欧美一区| 亚洲免费观看高清| 亚洲第一电影网| 天天影视涩香欲综合网| 久久er精品视频| 精品一区二区免费在线观看| 国产乱人伦偷精品视频不卡| 国产精品456| 99re视频这里只有精品| 色综合天天综合狠狠| 欧美日产国产精品| 欧美大片在线观看一区| 欧美国产丝袜视频| 自拍偷拍亚洲综合| 日韩不卡免费视频| 国产精品亚洲一区二区三区在线| 成人免费高清在线| 在线视频综合导航| 精品国产髙清在线看国产毛片| 久久一夜天堂av一区二区三区| 国产精品久久久久aaaa| 亚洲免费三区一区二区| 日日欢夜夜爽一区| 韩国女主播成人在线观看| 高潮精品一区videoshd| 色综合久久中文字幕| 日韩区在线观看| 国产蜜臀97一区二区三区| 日日夜夜精品视频免费| 精品在线一区二区三区| 99久久777色| av不卡免费电影| 欧美日韩一区二区三区四区| 中文字幕av资源一区| 亚洲午夜精品在线| 久久99久久99| 色网站国产精品| 日韩欧美国产高清| 亚洲欧洲www| 亚洲电影一区二区| 久久视频一区二区| 日韩和欧美一区二区三区| 成人免费看片app下载| 91精品婷婷国产综合久久性色| 欧美一区二区国产| 久久久久亚洲综合| 日本不卡1234视频| 一本大道av一区二区在线播放| 国产清纯美女被跳蛋高潮一区二区久久w | 视频一区欧美日韩| 精品一区二区三区在线观看 | 亚洲精品高清视频在线观看| 五月天亚洲精品| 欧美系列亚洲系列| 国产亚洲精品中文字幕| 极品销魂美女一区二区三区| 99热精品一区二区| 国产精品久久久久久久久久久免费看 | 午夜在线成人av| 成人a级免费电影| 中文字幕免费一区| 亚洲观看高清完整版在线观看| 国内精品久久久久影院色 | 成人欧美一区二区三区在线播放| 久久精品国产免费| 精品国产一二三| 午夜久久福利影院| 欧美日韩高清一区二区三区| 一色桃子久久精品亚洲|