⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 一个连接池的例子(来自jive)(4).txt

📁 一个新的采集工具 一个新的采集工具 一个新的采集工具
💻 TXT
字号:
作者:sonymusic
email: sonymusic@china.com
日期:2001-5-17 11:35:03
//文件:DbConnectionManager.java

package com.qingtuo.db.pool;

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

/**
 * Central manager of database connections.
 */
public class DbConnectionManager {

	private static DbConnectionProvider connectionProvider;
	private static Object providerLock = new Object();

	/**
	 * Returns a database connection from the currently active connection
	 * provider.
	 */
	public static Connection getConnection() {
		if (connectionProvider == null) {
			synchronized (providerLock) {
				if (connectionProvider == null) {
					//Create the connection provider -- for now, this is hardcoded. For
					//the next beta, I'll change this to load up the provider dynamically.
					connectionProvider = new DbConnectionDefaultPool();
					connectionProvider.start();
				}
			}
		}
		Connection con = connectionProvider.getConnection();
		if (con == null) {
			System.err.println("WARNING: DbConnectionManager.getConnection() failed to obtain a connection.");
		}
		return con;
	}

	/**
	 * Returns the current connection provider. The only case in which this
	 * method should be called is if more information about the current
	 * connection provider is needed. Database connections should always be
	 * obtained by calling the getConnection method of this class.
	 */
	public static DbConnectionProvider getDbConnectionProvider() {
		return connectionProvider;
	}

	/**
	 * Sets the connection provider. The old provider (if it exists) is shut
	 * down before the new one is started. A connection provider <b>should
	 * not</b> be started before being passed to the connection manager.
	 */
	public static void setDbConnectionProvider(DbConnectionProvider provider) {
		synchronized (providerLock) {
			if (connectionProvider != null) {
				connectionProvider.destroy();
				connectionProvider = null;
			}
			connectionProvider = provider;
			provider.start();
		}
	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -