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

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

?? connectionpool.java

?? 這是一個jsp聯合javabean的電話查詢系統。
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
package org.jzgs.telnumber.db;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.Date;

/**
 * 描述: 數據庫連接池類
 * Copyright (c) 2005-2008 Wang Xining
 * @author 王夕寧
 * @version 1.0
 */

public class ConnectionPool implements Runnable {

	private boolean _debug = false;

	private Thread runner;

	private Connection[] connPool;

	private int[] connStatus; // (0) available; (1) locked by the client; (2)

	// locked by the housekeeping thread

	private long[] connLockTime;

	private long[] connCreateTime;

	private String[] connID;

	private String dbdriver, dbserver, dbuser, dbpassword;

	private int currConnections, connLast, minconns, maxconns, maxconnMSec;

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

	private SQLWarning currSQLWarning;

	/**
	 * Creates a new Connection Broker<br>
	 * 
	 * @param dbdriver
	 *            JDBC driver. e.g. 'oracle.jdbc.driver.OracleDriver'<br>
	 * @param dbserver
	 *            JDBC connect string. e.g.
	 *            'jdbc:oracle:thin:@203.92.21.109:1526:orcl'<br>
	 * @param dbuser
	 *            Database login name. e.g. 'Scott'<br>
	 * @param dbpassword
	 *            Database password. e.g. 'Tiger'<br>
	 * @param minconns
	 *            Minimum number of connections to start with.<br>
	 * @param maxconns
	 *            Maximum number of connections in dynamic pool.<br>
	 * @param logFileString
	 *            Absolute path name for log file. e.g. 'c:\temp\mylog.log' <br>
	 * @param maxconntime
	 *            Time in hours between connection resets. (Reset does a basic
	 *            cleanup)<br>
	 */
	public ConnectionPool(String dbdriver, String dbserver, String dbuser,
			String dbpassword, int minconns, int maxconns, double maxconntime)
			throws IOException {
		connPool = new Connection[maxconns];
		connStatus = new int[maxconns];
		connLockTime = new long[maxconns];
		connCreateTime = new long[maxconns];
		connID = new String[maxconns];
		currConnections = minconns;
		this.maxconns = maxconns;
		this.dbdriver = dbdriver;
		this.dbserver = dbserver;
		this.dbuser = dbuser;
		this.dbpassword = dbpassword;
		maxconnMSec = (int) (maxconntime * 3600 * 1000);
		if (maxconnMSec < 60000) { // Recycle no less than 1 minute.
			maxconnMSec = 60000;
		}

//		System.out.println("Starting ConnectionPool:");
//		System.out.println("dbdriver = " + dbdriver);
//		System.out.println("dbserver = " + dbserver);
//		System.out.println("dbuser = " + dbuser);
//		System.out.println("minconnections = " + minconns);
//		System.out.println("maxconnections = " + maxconns);
//		System.out
//				.println("Total refresh interval = " + maxconntime + " hours");
//		System.out.println("-----------------------------------------");

		init();

		// Fire up the background housekeeping thread
		runner = new Thread(this);
		runner.start();
	} // End ConnectionPool()

	/**
	 * 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.
	 */
	private void init() throws IOException {

		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) {
					System.out
							.println("--->Attempt ("
									+ String.valueOf(i)
									+ " of "
									+ String.valueOf(dbLoop)
									+ ") failed to create new connections set at startup: ");
					System.out.println("    " + e);
					System.out.println("    Will try again in 15 seconds...");
					try {
						Thread.sleep(15000);
					} catch (InterruptedException e1) {
					}
				}
			}
			if (!connectionsSucceeded) { // All attempts at connecting to db
				// exhausted
				System.out
						.println("\r\nAll attempts at connecting to Database exhausted");
				throw new IOException();
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new IOException();
		}
	}

	private void createConn(int i) throws SQLException {
		Date now = new Date();
		try {
			Class.forName(dbdriver);
			connPool[i] = DriverManager.getConnection(dbserver, dbuser,
					dbpassword);
			connStatus[i] = 0;
			connID[i] = connPool[i].toString();
			connLockTime[i] = 0;
			connCreateTime[i] = now.getTime();

//			System.out.println(now.toString() + "  Opening connection "
//					+ String.valueOf(i) + " " + connPool[i].toString() + ":");
		} catch (ClassNotFoundException e2) {
			e2.printStackTrace();
			throw new SQLException(e2.getMessage());
		}
	} // createConn()

	/**
	 * 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() {
		Statement stmt = null;
		String currCatalog = null;

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

			for (int i = 0; i < currConnections; i++) { // Do for each
				// connection
				long age = System.currentTimeMillis() - connCreateTime[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("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 {
//						System.out.println(new Date().toString()
//								+ " ***** Recycling connection "
//								+ String.valueOf(i) + ":");

						connPool[i].close();
						createConn(i);
					} catch (SQLException e1) {
						System.out.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;
			}

		} // for(;;)
	} // 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.
	 */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本网站在线观看一区二区三区 | 国产999精品久久久久久绿帽| 丰满白嫩尤物一区二区| 欧美在线一二三四区| 久久久久久久久99精品| 亚洲18影院在线观看| 成人午夜av影视| 欧美v日韩v国产v| 午夜精品影院在线观看| 99国产精品久久久久| 久久夜色精品国产欧美乱极品| 一区二区三区日本| av在线一区二区| 国产农村妇女毛片精品久久麻豆 | 欧美欧美欧美欧美| 亚洲视频免费观看| 成人午夜在线免费| 久久久精品综合| 国内精品视频一区二区三区八戒| 欧美日韩视频不卡| 亚洲与欧洲av电影| 欧美性大战久久| 亚洲蜜桃精久久久久久久| 99视频精品全部免费在线| 久久久噜噜噜久噜久久综合| 激情综合色丁香一区二区| 7777精品伊人久久久大香线蕉经典版下载 | 日韩精品资源二区在线| 日韩电影在线免费看| 欧美久久久影院| 亚洲电影第三页| 在线播放欧美女士性生活| 亚洲一区二区三区美女| 在线观看av一区| 一区二区三区四区精品在线视频| 99综合影院在线| 国产精品乱码一区二区三区软件| 国产精品888| 国产欧美日韩在线视频| 成人亚洲一区二区一| 国产精品久久久久久久久晋中| 国产成人精品免费一区二区| 久久精品视频免费观看| 狠狠色丁香久久婷婷综合丁香| 欧美成人a视频| 国产精品一区二区x88av| 精品成人免费观看| 国产经典欧美精品| 亚洲视频一区在线| 欧美日韩国产综合视频在线观看| 午夜精品福利在线| 精品粉嫩aⅴ一区二区三区四区| 另类小说综合欧美亚洲| 久久久久久久久久看片| 国产精品亚洲成人| 自拍偷拍欧美激情| 欧美亚洲另类激情小说| 免费日本视频一区| 久久夜色精品一区| 91丨porny丨国产| 亚洲国产视频在线| 精品少妇一区二区三区视频免付费 | 亚洲一区二区视频| 日韩一级高清毛片| 国产91高潮流白浆在线麻豆 | 国产在线一区二区| 国产精品素人视频| 欧美视频一区在线| 国产在线精品一区在线观看麻豆| 1区2区3区欧美| 日韩免费一区二区| 色综合久久综合网欧美综合网| 亚洲国产日韩在线一区模特| 久久久久97国产精华液好用吗| 色婷婷国产精品综合在线观看| 日韩精彩视频在线观看| 国产精品久久久久久亚洲伦| 欧美一区二区在线不卡| 成人18精品视频| 免费在线看成人av| 亚洲欧美视频在线观看视频| 精品国产乱码久久久久久蜜臀| 欧美亚洲国产一区在线观看网站 | 国产日韩高清在线| 欧美日韩电影一区| 波多野结衣欧美| 国产永久精品大片wwwapp | 欧美午夜精品理论片a级按摩| 国产一区二区三区视频在线播放| 一区二区欧美在线观看| 国产人成亚洲第一网站在线播放| 欧美一区二区三区四区五区| 91福利国产精品| 91在线观看免费视频| 国产精品99久久久久久有的能看| 日韩av电影天堂| 一级精品视频在线观看宜春院| 国产精品久久久久久久久免费樱桃| 欧美激情一区不卡| 精品国产一区二区三区四区四 | 色欧美片视频在线观看| 国产尤物一区二区| 久久99久久99小草精品免视看| 亚洲www啪成人一区二区麻豆| 亚洲免费观看高清完整| 综合在线观看色| 国产精品美女视频| 国产精品福利一区| 国产精品狼人久久影院观看方式| 久久精品在线免费观看| 精品免费国产二区三区| 欧美电影免费观看高清完整版 | 久久超碰97人人做人人爱| 天天综合网 天天综合色| 亚洲123区在线观看| 亚洲成人在线网站| 午夜婷婷国产麻豆精品| 午夜伦理一区二区| 日韩国产欧美三级| 蜜桃av噜噜一区| 国产一区三区三区| 国产乱码一区二区三区| 国产精品一区免费在线观看| 国产精品自拍三区| 成人18视频在线播放| 91美女视频网站| 欧美亚洲动漫精品| 69成人精品免费视频| 精品粉嫩超白一线天av| 国产精品国产自产拍高清av王其| 日韩美女精品在线| 亚洲精品视频在线观看网站| 亚洲码国产岛国毛片在线| 一区二区高清视频在线观看| 亚洲一区二区欧美| 免费人成黄页网站在线一区二区| 男人的天堂亚洲一区| 国产.欧美.日韩| 色婷婷久久久亚洲一区二区三区| 欧美高清视频一二三区 | 国产精品亚洲综合一区在线观看| 成人黄色国产精品网站大全在线免费观看| 岛国精品在线播放| 欧美三级视频在线观看| 欧美xxxx在线观看| 中文字幕日韩一区| 日本三级亚洲精品| 成人伦理片在线| 69成人精品免费视频| 国产欧美日韩精品一区| 亚洲一区精品在线| 韩国av一区二区三区四区| 色综合久久九月婷婷色综合| 91麻豆精品国产91久久久 | 午夜精品一区在线观看| 国产精品羞羞答答xxdd| 欧美视频在线一区| 中文字幕乱码一区二区免费| 日韩国产欧美三级| aa级大片欧美| 久久一区二区视频| 亚洲不卡在线观看| 99精品久久只有精品| 精品久久久影院| 午夜久久久久久电影| proumb性欧美在线观看| 日韩一级片在线播放| 亚洲激情成人在线| 国产白丝精品91爽爽久久| 91精品国产91久久综合桃花| 亚洲人精品一区| 成人理论电影网| 久久伊人蜜桃av一区二区| 日韩国产精品久久久久久亚洲| 99这里都是精品| 国产精品久久久爽爽爽麻豆色哟哟 | 欧美不卡视频一区| 亚洲国产一区在线观看| 91美女片黄在线观看91美女| 欧美激情一区二区三区全黄| 精品一区二区三区免费观看| 9191精品国产综合久久久久久| 亚洲三级在线观看| 国产成人午夜精品5599| 日韩欧美一区电影| 奇米四色…亚洲| 欧美精品精品一区| 亚洲高清视频的网址| 色噜噜夜夜夜综合网| 综合欧美一区二区三区| 99久久99久久精品免费看蜜桃| 欧美激情中文不卡| av在线免费不卡| 国产精品灌醉下药二区| gogo大胆日本视频一区| 国产精品久久久久久福利一牛影视 | 高清不卡在线观看| 国产亚洲成年网址在线观看| 国产精品亚洲一区二区三区妖精| 欧美精品一区二区三区四区|