- 浏览: 91718 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
guoyunsky:
不错,但ubuntu下只要一行命令即可:sudo aptitu ...
ubuntu 安装 Pidgin -
komei:
#连接设置jdbc.driverClassName=oracl ...
derby dbcp -
wsbjwjt:
我要试一下
window subversion -
komei:
### This file is an example aut ...
SVN -
komei:
http://jhcore.com/2007/06/04/in ...
ubuntu 安装 Pidgin
import java.util.concurrent.Semaphore;
import java.util.Stack;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.concurrent.TimeUnit;
import javax.sql.ConnectionPoolDataSource;
import javax.sql.ConnectionEvent;
import javax.sql.ConnectionEventListener;
import javax.sql.PooledConnection;
/**
* A simple standalone JDBC connection pool manager.
* <p>
* The public methods of this class are thread-safe.
* <p>
* Author: Christian d'Heureuse (<a
* href="http://www.source-code.biz">www.source-code.biz</a>)<br>
* License: <a href="http://www.gnu.org/licenses/lgpl.html">LGPL</a>.
* <p>
* 2007-06-21: Constructor with a timeout parameter added.
*/
public class MiniConnectionPoolManager {
private ConnectionPoolDataSource dataSource;
private int maxConnections;
private int timeout;
private PrintWriter logWriter;
private Semaphore semaphore;
private Stack<PooledConnection> recycledConnections;
private int activeConnections;
private PoolConnectionEventListener poolConnectionEventListener;
private boolean isDisposed;
/**
* Thrown in {@link #getConnection()} when no free connection becomes available
* within <code>timeout</code> seconds.
*/
public static class TimeoutException extends RuntimeException {
private static final long serialVersionUID = 1;
public TimeoutException () {
super ("Timeout while waiting for a free database connection."); }}
/**
* Constructs a MiniConnectionPoolManager object with a timeout of 60 seconds.
*
* @param dataSource
* the data source for the connections.
* @param maxConnections
* the maximum number of connections.
*/
public MiniConnectionPoolManager (ConnectionPoolDataSource dataSource, int maxConnections) {
this (dataSource, maxConnections, 60); }
/**
* Constructs a MiniConnectionPoolManager object.
*
* @param dataSource
* the data source for the connections.
* @param maxConnections
* the maximum number of connections.
* @param timeout
* the maximum time in seconds to wait for a free connection.
*/
public MiniConnectionPoolManager (ConnectionPoolDataSource dataSource, int maxConnections, int timeout) {
this.dataSource = dataSource;
this.maxConnections = maxConnections;
this.timeout = timeout;
try {
logWriter = dataSource.getLogWriter(); }
catch (SQLException e) {}
if (maxConnections < 1) throw new IllegalArgumentException("Invalid maxConnections value.");
semaphore = new Semaphore(maxConnections,true);
recycledConnections = new Stack<PooledConnection>();
poolConnectionEventListener = new PoolConnectionEventListener(); }
/**
* Closes all unused pooled connections.
*/
public synchronized void dispose() throws SQLException {
if (isDisposed) return;
isDisposed = true;
SQLException e = null;
while (!recycledConnections.isEmpty()) {
PooledConnection pconn = recycledConnections.pop();
try {
pconn.close(); }
catch (SQLException e2) {
if (e == null) e = e2; }}
if (e != null) throw e; }
/**
* Retrieves a connection from the connection pool. If
* <code>maxConnections</code> connections are already in use, the method
* waits until a connection becomes available or <code>timeout</code> seconds
* elapsed. When the application is finished using the connection, it must close
* it in order to return it to the pool.
*
* @return a new Connection object.
* @throws TimeoutException
* when no connection becomes available within <code>timeout</code>
* seconds.
*/
public Connection getConnection() throws SQLException {
// This routine is unsynchronized, because semaphore.acquire() may block.
synchronized (this) {
if (isDisposed) throw new IllegalStateException("Connection pool has been disposed."); }
try {
if (!semaphore.tryAcquire(timeout,TimeUnit.SECONDS))
throw new TimeoutException(); }
catch (InterruptedException e) {
throw new RuntimeException("Interrupted while waiting for a database connection.",e); }
boolean ok = false;
try {
Connection conn = getConnection2();
ok = true;
return conn; }
finally {
if (!ok) semaphore.release(); }}
private synchronized Connection getConnection2() throws SQLException {
if (isDisposed) throw new IllegalStateException("Connection pool has been disposed."); // test
// again
// with
// lock
PooledConnection pconn;
if (!recycledConnections.empty()) {
pconn = recycledConnections.pop(); }
else {
pconn = dataSource.getPooledConnection(); }
Connection conn = pconn.getConnection();
activeConnections++;
pconn.addConnectionEventListener (poolConnectionEventListener);
assertInnerState();
return conn; }
private synchronized void recycleConnection (PooledConnection pconn) {
if (isDisposed) { disposeConnection (pconn); return; }
if (activeConnections <= 0) throw new AssertionError();
activeConnections--;
semaphore.release();
recycledConnections.push (pconn);
assertInnerState(); }
private synchronized void disposeConnection (PooledConnection pconn) {
if (activeConnections <= 0) throw new AssertionError();
activeConnections--;
semaphore.release();
closeConnectionNoEx (pconn);
assertInnerState(); }
private void closeConnectionNoEx (PooledConnection pconn) {
try {
pconn.close(); }
catch (SQLException e) {
log ("Error while closing database connection: "+e.toString()); }}
private void log (String msg) {
String s = "MiniConnectionPoolManager: "+msg;
try {
if (logWriter == null)
System.err.println (s);
else
logWriter.println (s); }
catch (Exception e) {}}
private void assertInnerState() {
if (activeConnections < 0) throw new AssertionError();
if (activeConnections+recycledConnections.size() > maxConnections) throw new AssertionError();
if (activeConnections+semaphore.availablePermits() > maxConnections) throw new AssertionError(); }
private class PoolConnectionEventListener implements ConnectionEventListener {
public void connectionClosed (ConnectionEvent event) {
PooledConnection pconn = (PooledConnection)event.getSource();
pconn.removeConnectionEventListener (this);
recycleConnection (pconn); }
public void connectionErrorOccurred(ConnectionEvent event) {
PooledConnection pconn = (PooledConnection)event.getSource();
pconn.removeConnectionEventListener (this);
disposeConnection (pconn); }}
/**
* Returns the number of active (open) connections of this pool. This is the
* number of <code>Connection</code> objects that have been issued by
* {@link #getConnection()} for which <code>Connection.close()</code> has not
* yet been called.
*
* @return the number of active connections.
*/
public synchronized int getActiveConnections() {
return activeConnections; }
} // end class MiniConnectionPoolManager
// Test program for the MiniConnectionPoolManager class.
import java.io.PrintWriter;
import java.lang.Thread;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;
import javax.sql.ConnectionPoolDataSource;
import com.oval.research.connpool.MiniConnectionPoolManager;
public class TestMiniConnectionPoolManager {
private static final int maxConnections = 8; // number of connections
private static final int noOfThreads = 50; // number of worker threads
private static final int processingTime = 30; // total processing time of
// the test program in
// seconds
private static final int threadPauseTime1 = 100; // max. thread pause
// time in microseconds,
// without a connection
private static final int threadPauseTime2 = 100; // max. thread pause
// time in microseconds,
// with a connection
private static MiniConnectionPoolManager poolMgr;
private static WorkerThread[] threads;
private static boolean shutdownFlag;
private static Object shutdownObj = new Object();
private static Random random = new Random();
private static class WorkerThread extends Thread {
public int threadNo;
public void run() {
threadMain(threadNo);
}
};
private static ConnectionPoolDataSource createDataSource() throws Exception {
// Version for H2:
/*
* org.h2.jdbcx.JdbcDataSource dataSource = new
* org.h2.jdbcx.JdbcDataSource(); dataSource.setURL
* ("jdbc:h2:file:c:/temp/temp_TestMiniConnectionPoolManagerDB;DB_CLOSE_DELAY=-1");
*/
// Version for Apache Derby:
org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource dataSource = new org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource();
dataSource
.setDatabaseName("e:/mimiConnection/temp_TestMiniConnectionPoolManagerDB");
dataSource.setCreateDatabase("create");
dataSource.setLogWriter(new PrintWriter(System.out));
// Versioo for JTDS:
/*
* net.sourceforge.jtds.jdbcx.JtdsDataSource dataSource = new
* net.sourceforge.jtds.jdbcx.JtdsDataSource(); dataSource.setAppName
* ("TestMiniConnectionPoolManager"); dataSource.setDatabaseName
* ("Northwind"); dataSource.setServerName ("localhost");
* dataSource.setUser ("sa"); dataSource.setPassword
* (System.getProperty("saPassword"));
*/
// Version for the Microsoft SQL Server driver (sqljdbc.jar):
/*
* // The sqljdbc 1.1 documentation, chapter "Using Connection Pooling",
* recommends to use // SQLServerXADataSource instead of
* SQLServerConnectionPoolDataSource, even when no // distributed
* transactions are used.
* com.microsoft.sqlserver.jdbc.SQLServerXADataSource dataSource = new
* com.microsoft.sqlserver.jdbc.SQLServerXADataSource();
* dataSource.setApplicationName ("TestMiniConnectionPoolManager");
* dataSource.setDatabaseName ("Northwind"); dataSource.setServerName
* ("localhost"); dataSource.setUser ("sa"); dataSource.setPassword
* (System.getProperty("saPassword")); dataSource.setLogWriter (new
* PrintWriter(System.out));
*/
return dataSource;
}
public static void main(String[] args) throws Exception {
System.out.println("Program started.");
ConnectionPoolDataSource dataSource = createDataSource();
poolMgr = new MiniConnectionPoolManager(dataSource, maxConnections);
initDb();
startWorkerThreads();
pause(processingTime * 1000000);
System.out.println("\nStopping threads.");
stopWorkerThreads();
System.out.println("\nAll threads stopped.");
poolMgr.dispose();
System.out.println("Program completed.");
}
private static void startWorkerThreads() {
threads = new WorkerThread[noOfThreads];
for (int threadNo = 0; threadNo < noOfThreads; threadNo++) {
WorkerThread thread = new WorkerThread();
threads[threadNo] = thread;
thread.threadNo = threadNo;
thread.start();
}
}
private static void stopWorkerThreads() throws Exception {
setShutdownFlag();
for (int threadNo = 0; threadNo < noOfThreads; threadNo++) {
threads[threadNo].join();
}
}
private static void setShutdownFlag() {
synchronized (shutdownObj) {
shutdownFlag = true;
shutdownObj.notifyAll();
}
}
private static void threadMain(int threadNo) {
try {
threadMain2(threadNo);
} catch (Throwable e) {
System.out.println("\nException in thread " + threadNo + ": " + e);
e.printStackTrace(System.out);
setShutdownFlag();
}
}
private static void threadMain2(int threadNo) throws Exception {
// System.out.println ("Thread "+threadNo+" started.");
while (true) {
if (!pauseRandom(threadPauseTime1))
return;
threadTask(threadNo);
}
}
private static void threadTask(int threadNo) throws Exception {
Connection conn = null;
try {
conn = poolMgr.getConnection();
if (shutdownFlag)
return;
System.out.print(threadNo + " ");
incrementThreadCounter(conn, threadNo);
pauseRandom(threadPauseTime2);
} finally {
if (conn != null)
conn.close();
}
}
private static boolean pauseRandom(int maxPauseTime) throws Exception {
return pause(random.nextInt(maxPauseTime));
}
private static boolean pause(int pauseTime) throws Exception {
synchronized (shutdownObj) {
if (shutdownFlag)
return false;
if (pauseTime <= 0)
return true;
int ms = pauseTime / 1000;
int ns = (pauseTime % 1000) * 1000;
shutdownObj.wait(ms, ns);
}
return true;
}
private static void initDb() throws SQLException {
Connection conn = null;
try {
conn = poolMgr.getConnection();
System.out.println("initDb connected");
initDb2(conn);
} finally {
if (conn != null)
conn.close();
}
System.out.println("initDb done");
}
private static void initDb2(Connection conn) throws SQLException {
execSqlNoErr(conn, "drop table temp");
execSql(conn, "create table temp (threadNo integer, ctr integer)");
for (int i = 0; i < noOfThreads; i++)
execSql(conn, "insert into temp values(" + i + ",0)");
}
private static void incrementThreadCounter(Connection conn, int threadNo)
throws SQLException {
execSql(conn, "update temp set ctr = ctr + 1 where threadNo="
+ threadNo);
}
private static void execSqlNoErr(Connection conn, String sql) {
try {
execSql(conn, sql);
} catch (SQLException e) {
}
}
private static void execSql(Connection conn, String sql)
throws SQLException {
Statement st = null;
try {
st = conn.createStatement();
st.executeUpdate(sql);
} finally {
if (st != null)
st.close();
}
}
} // end class TestMiniConnectionPoolManager
import java.util.Stack;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.concurrent.TimeUnit;
import javax.sql.ConnectionPoolDataSource;
import javax.sql.ConnectionEvent;
import javax.sql.ConnectionEventListener;
import javax.sql.PooledConnection;
/**
* A simple standalone JDBC connection pool manager.
* <p>
* The public methods of this class are thread-safe.
* <p>
* Author: Christian d'Heureuse (<a
* href="http://www.source-code.biz">www.source-code.biz</a>)<br>
* License: <a href="http://www.gnu.org/licenses/lgpl.html">LGPL</a>.
* <p>
* 2007-06-21: Constructor with a timeout parameter added.
*/
public class MiniConnectionPoolManager {
private ConnectionPoolDataSource dataSource;
private int maxConnections;
private int timeout;
private PrintWriter logWriter;
private Semaphore semaphore;
private Stack<PooledConnection> recycledConnections;
private int activeConnections;
private PoolConnectionEventListener poolConnectionEventListener;
private boolean isDisposed;
/**
* Thrown in {@link #getConnection()} when no free connection becomes available
* within <code>timeout</code> seconds.
*/
public static class TimeoutException extends RuntimeException {
private static final long serialVersionUID = 1;
public TimeoutException () {
super ("Timeout while waiting for a free database connection."); }}
/**
* Constructs a MiniConnectionPoolManager object with a timeout of 60 seconds.
*
* @param dataSource
* the data source for the connections.
* @param maxConnections
* the maximum number of connections.
*/
public MiniConnectionPoolManager (ConnectionPoolDataSource dataSource, int maxConnections) {
this (dataSource, maxConnections, 60); }
/**
* Constructs a MiniConnectionPoolManager object.
*
* @param dataSource
* the data source for the connections.
* @param maxConnections
* the maximum number of connections.
* @param timeout
* the maximum time in seconds to wait for a free connection.
*/
public MiniConnectionPoolManager (ConnectionPoolDataSource dataSource, int maxConnections, int timeout) {
this.dataSource = dataSource;
this.maxConnections = maxConnections;
this.timeout = timeout;
try {
logWriter = dataSource.getLogWriter(); }
catch (SQLException e) {}
if (maxConnections < 1) throw new IllegalArgumentException("Invalid maxConnections value.");
semaphore = new Semaphore(maxConnections,true);
recycledConnections = new Stack<PooledConnection>();
poolConnectionEventListener = new PoolConnectionEventListener(); }
/**
* Closes all unused pooled connections.
*/
public synchronized void dispose() throws SQLException {
if (isDisposed) return;
isDisposed = true;
SQLException e = null;
while (!recycledConnections.isEmpty()) {
PooledConnection pconn = recycledConnections.pop();
try {
pconn.close(); }
catch (SQLException e2) {
if (e == null) e = e2; }}
if (e != null) throw e; }
/**
* Retrieves a connection from the connection pool. If
* <code>maxConnections</code> connections are already in use, the method
* waits until a connection becomes available or <code>timeout</code> seconds
* elapsed. When the application is finished using the connection, it must close
* it in order to return it to the pool.
*
* @return a new Connection object.
* @throws TimeoutException
* when no connection becomes available within <code>timeout</code>
* seconds.
*/
public Connection getConnection() throws SQLException {
// This routine is unsynchronized, because semaphore.acquire() may block.
synchronized (this) {
if (isDisposed) throw new IllegalStateException("Connection pool has been disposed."); }
try {
if (!semaphore.tryAcquire(timeout,TimeUnit.SECONDS))
throw new TimeoutException(); }
catch (InterruptedException e) {
throw new RuntimeException("Interrupted while waiting for a database connection.",e); }
boolean ok = false;
try {
Connection conn = getConnection2();
ok = true;
return conn; }
finally {
if (!ok) semaphore.release(); }}
private synchronized Connection getConnection2() throws SQLException {
if (isDisposed) throw new IllegalStateException("Connection pool has been disposed."); // test
// again
// with
// lock
PooledConnection pconn;
if (!recycledConnections.empty()) {
pconn = recycledConnections.pop(); }
else {
pconn = dataSource.getPooledConnection(); }
Connection conn = pconn.getConnection();
activeConnections++;
pconn.addConnectionEventListener (poolConnectionEventListener);
assertInnerState();
return conn; }
private synchronized void recycleConnection (PooledConnection pconn) {
if (isDisposed) { disposeConnection (pconn); return; }
if (activeConnections <= 0) throw new AssertionError();
activeConnections--;
semaphore.release();
recycledConnections.push (pconn);
assertInnerState(); }
private synchronized void disposeConnection (PooledConnection pconn) {
if (activeConnections <= 0) throw new AssertionError();
activeConnections--;
semaphore.release();
closeConnectionNoEx (pconn);
assertInnerState(); }
private void closeConnectionNoEx (PooledConnection pconn) {
try {
pconn.close(); }
catch (SQLException e) {
log ("Error while closing database connection: "+e.toString()); }}
private void log (String msg) {
String s = "MiniConnectionPoolManager: "+msg;
try {
if (logWriter == null)
System.err.println (s);
else
logWriter.println (s); }
catch (Exception e) {}}
private void assertInnerState() {
if (activeConnections < 0) throw new AssertionError();
if (activeConnections+recycledConnections.size() > maxConnections) throw new AssertionError();
if (activeConnections+semaphore.availablePermits() > maxConnections) throw new AssertionError(); }
private class PoolConnectionEventListener implements ConnectionEventListener {
public void connectionClosed (ConnectionEvent event) {
PooledConnection pconn = (PooledConnection)event.getSource();
pconn.removeConnectionEventListener (this);
recycleConnection (pconn); }
public void connectionErrorOccurred(ConnectionEvent event) {
PooledConnection pconn = (PooledConnection)event.getSource();
pconn.removeConnectionEventListener (this);
disposeConnection (pconn); }}
/**
* Returns the number of active (open) connections of this pool. This is the
* number of <code>Connection</code> objects that have been issued by
* {@link #getConnection()} for which <code>Connection.close()</code> has not
* yet been called.
*
* @return the number of active connections.
*/
public synchronized int getActiveConnections() {
return activeConnections; }
} // end class MiniConnectionPoolManager
// Test program for the MiniConnectionPoolManager class.
import java.io.PrintWriter;
import java.lang.Thread;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;
import javax.sql.ConnectionPoolDataSource;
import com.oval.research.connpool.MiniConnectionPoolManager;
public class TestMiniConnectionPoolManager {
private static final int maxConnections = 8; // number of connections
private static final int noOfThreads = 50; // number of worker threads
private static final int processingTime = 30; // total processing time of
// the test program in
// seconds
private static final int threadPauseTime1 = 100; // max. thread pause
// time in microseconds,
// without a connection
private static final int threadPauseTime2 = 100; // max. thread pause
// time in microseconds,
// with a connection
private static MiniConnectionPoolManager poolMgr;
private static WorkerThread[] threads;
private static boolean shutdownFlag;
private static Object shutdownObj = new Object();
private static Random random = new Random();
private static class WorkerThread extends Thread {
public int threadNo;
public void run() {
threadMain(threadNo);
}
};
private static ConnectionPoolDataSource createDataSource() throws Exception {
// Version for H2:
/*
* org.h2.jdbcx.JdbcDataSource dataSource = new
* org.h2.jdbcx.JdbcDataSource(); dataSource.setURL
* ("jdbc:h2:file:c:/temp/temp_TestMiniConnectionPoolManagerDB;DB_CLOSE_DELAY=-1");
*/
// Version for Apache Derby:
org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource dataSource = new org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource();
dataSource
.setDatabaseName("e:/mimiConnection/temp_TestMiniConnectionPoolManagerDB");
dataSource.setCreateDatabase("create");
dataSource.setLogWriter(new PrintWriter(System.out));
// Versioo for JTDS:
/*
* net.sourceforge.jtds.jdbcx.JtdsDataSource dataSource = new
* net.sourceforge.jtds.jdbcx.JtdsDataSource(); dataSource.setAppName
* ("TestMiniConnectionPoolManager"); dataSource.setDatabaseName
* ("Northwind"); dataSource.setServerName ("localhost");
* dataSource.setUser ("sa"); dataSource.setPassword
* (System.getProperty("saPassword"));
*/
// Version for the Microsoft SQL Server driver (sqljdbc.jar):
/*
* // The sqljdbc 1.1 documentation, chapter "Using Connection Pooling",
* recommends to use // SQLServerXADataSource instead of
* SQLServerConnectionPoolDataSource, even when no // distributed
* transactions are used.
* com.microsoft.sqlserver.jdbc.SQLServerXADataSource dataSource = new
* com.microsoft.sqlserver.jdbc.SQLServerXADataSource();
* dataSource.setApplicationName ("TestMiniConnectionPoolManager");
* dataSource.setDatabaseName ("Northwind"); dataSource.setServerName
* ("localhost"); dataSource.setUser ("sa"); dataSource.setPassword
* (System.getProperty("saPassword")); dataSource.setLogWriter (new
* PrintWriter(System.out));
*/
return dataSource;
}
public static void main(String[] args) throws Exception {
System.out.println("Program started.");
ConnectionPoolDataSource dataSource = createDataSource();
poolMgr = new MiniConnectionPoolManager(dataSource, maxConnections);
initDb();
startWorkerThreads();
pause(processingTime * 1000000);
System.out.println("\nStopping threads.");
stopWorkerThreads();
System.out.println("\nAll threads stopped.");
poolMgr.dispose();
System.out.println("Program completed.");
}
private static void startWorkerThreads() {
threads = new WorkerThread[noOfThreads];
for (int threadNo = 0; threadNo < noOfThreads; threadNo++) {
WorkerThread thread = new WorkerThread();
threads[threadNo] = thread;
thread.threadNo = threadNo;
thread.start();
}
}
private static void stopWorkerThreads() throws Exception {
setShutdownFlag();
for (int threadNo = 0; threadNo < noOfThreads; threadNo++) {
threads[threadNo].join();
}
}
private static void setShutdownFlag() {
synchronized (shutdownObj) {
shutdownFlag = true;
shutdownObj.notifyAll();
}
}
private static void threadMain(int threadNo) {
try {
threadMain2(threadNo);
} catch (Throwable e) {
System.out.println("\nException in thread " + threadNo + ": " + e);
e.printStackTrace(System.out);
setShutdownFlag();
}
}
private static void threadMain2(int threadNo) throws Exception {
// System.out.println ("Thread "+threadNo+" started.");
while (true) {
if (!pauseRandom(threadPauseTime1))
return;
threadTask(threadNo);
}
}
private static void threadTask(int threadNo) throws Exception {
Connection conn = null;
try {
conn = poolMgr.getConnection();
if (shutdownFlag)
return;
System.out.print(threadNo + " ");
incrementThreadCounter(conn, threadNo);
pauseRandom(threadPauseTime2);
} finally {
if (conn != null)
conn.close();
}
}
private static boolean pauseRandom(int maxPauseTime) throws Exception {
return pause(random.nextInt(maxPauseTime));
}
private static boolean pause(int pauseTime) throws Exception {
synchronized (shutdownObj) {
if (shutdownFlag)
return false;
if (pauseTime <= 0)
return true;
int ms = pauseTime / 1000;
int ns = (pauseTime % 1000) * 1000;
shutdownObj.wait(ms, ns);
}
return true;
}
private static void initDb() throws SQLException {
Connection conn = null;
try {
conn = poolMgr.getConnection();
System.out.println("initDb connected");
initDb2(conn);
} finally {
if (conn != null)
conn.close();
}
System.out.println("initDb done");
}
private static void initDb2(Connection conn) throws SQLException {
execSqlNoErr(conn, "drop table temp");
execSql(conn, "create table temp (threadNo integer, ctr integer)");
for (int i = 0; i < noOfThreads; i++)
execSql(conn, "insert into temp values(" + i + ",0)");
}
private static void incrementThreadCounter(Connection conn, int threadNo)
throws SQLException {
execSql(conn, "update temp set ctr = ctr + 1 where threadNo="
+ threadNo);
}
private static void execSqlNoErr(Connection conn, String sql) {
try {
execSql(conn, sql);
} catch (SQLException e) {
}
}
private static void execSql(Connection conn, String sql)
throws SQLException {
Statement st = null;
try {
st = conn.createStatement();
st.executeUpdate(sql);
} finally {
if (st != null)
st.close();
}
}
} // end class TestMiniConnectionPoolManager
相关推荐
迷你连接池管理器(MiniConnectionPoolManager)是一个小型且轻量级的数据库连接池实现,专为简化JDBC连接管理而设计。它提供了一种有效的方式,以优化数据库访问性能和资源利用,尤其是在多线程环境中。连接池是...
6. **DbConnectionBroker** 和 **MiniConnectionPoolManager**:这两种轻量级连接池实现相对简单,适用于对性能要求不高的应用场景。 #### 四、连接池的技术特点 1. **API设计**: - DBCP和C3P0因其广泛的使用而...
7. **MiniConnectionPoolManager**:这是Apache Commons DBCP项目的一部分,它是一个简单的连接池管理器,适用于小型应用。它提供了基本的连接池管理功能,如连接初始化、最大连接限制等。 8. **Proxool_0.9.1**:...
9. **MiniConnectionPoolManager**:轻量级且无第三方依赖的JDBC数据库连接池,适用于简单场景。 10. **BoneCP**:快速且开源的连接池,比C3P0和DBCP快25倍,适合性能敏感的应用。 在配置Hibernate与连接池的整合...
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
,IGBT结温估算 模型见另一个发布
"S7-200 PLC驱动的智能粮仓系统:带解释的接线图与组态画面原理详解",S7-200 mcgs基于plc的自动智能粮仓系统 带解释的梯形图接线图原理图图纸,io分配,组态画面 ,S7-200; PLC; 自动智能粮仓系统; 梯形图接线图; 原理图图纸; IO分配; 组态画面,基于S7-200 PLC的智能粮仓系统设计与实现
手机编程-1738391379497.jpg
,rk3399pro,rk3568,车载方案设计,4路AHD-1080P摄像头输入,防撞识别,助力车泥头车安全运输
,CAD、DXF导图,自动进行位置路径规划,源码可进行简单功能添加实现设备所需功能,已经在冲孔机,点胶机上应用,性价比超高。 打孔机实测一分钟1400个孔
,电机控制资料-- 注:本驱动器适合于直流有感无刷电机 功能特点 支持电压9V~36V,额定输出电流5A 支持电位器、开关、0~3.3V模拟信号范围、0 3.3 5 24V逻辑电平、PWM 频率 脉冲信号、RS485多种输入信号 支持占空比调速(调压)、速度闭环控制(稳速)、电流控制(稳流)多种调速方式 支持按键控制正反转速度,启停 特色功能 1. 霍尔自学习 电机的三相线和三霍尔信号线可不按顺序连接,驱动器可自动对电机霍尔顺序进行学习。 2. 稳速控制响应时间短 稳速控制时电机由正转2000RPM切为反转2000RPM,用时约1.0s,电机切过程平稳 3. 极低速稳速控制 电机进行极低速稳速控制,电机稳速控制均匀,无忽快忽慢现象。
《HFSS同轴馈电矩形微带天线的模型制作与参数优化:从结果中学习,使用HFSS软件包进行实践的详细教程》,HFSS同轴馈电矩形微带天线 天线模型,附带结果,可改参数,HFSS软件包 (有教程,具体到每一步,可以自己做出来) ,HFSS; 同轴馈电; 矩形微带天线; 可改参数; HFSS软件包; 附带结果; 教程,HFSS软件包:可改参微带天线模型附带结果教程
"基于第二篇文章求解方法,改进粒子群算法在微电网综合能源优化调度的应用与复现代码展示——第一篇模型的参考与实践",基于改进粒子群算法微电网综合能源优化调度 求解方法主要参考第二篇文章 模型参照第一篇 复现代码 ,核心关键词: 基于改进粒子群算法; 微电网综合能源优化调度; 求解方法; 第二篇文章; 模型; 第一篇文章; 复现代码;,基于第二篇求解方法的改进粒子群算法在微电网综合能源优化调度中的应用研究
基于Comsol模拟的三层顶板随机裂隙浆液扩散模型:考虑重力影响的瞬态扩散规律分析,Comsol模拟,考虑三层顶板包含随机裂隙的浆液扩散模型,考虑浆液重力的影响,模型采用的DFN插件建立随机裂隙,采用达西定律模块中的储水模型为控制方程,分析不同注浆压力条件下的浆液扩散规律,建立瞬态模型 ,Comsol模拟; 随机裂隙浆液扩散模型; 浆液重力影响; DFN插件; 达西定律模块储水模型; 注浆压力条件; 浆液扩散规律; 瞬态模型,Comsol浆液扩散模型:随机裂隙下考虑重力的瞬态扩散分析
"基于S7-200 PLC与MCGS组态的五层电梯控制系统设计与实现:带详细接线图、IO分配及组态画面解析",S7-200 PLC和MCGS组态5层电梯五层电梯PLC控制系统 带解释的梯形图接线图原理图图纸,io分配,组态画面 ,核心关键词:S7-200 PLC; MCGS组态; 五层电梯; PLC控制系统; 梯形图接线图; IO分配; 组态画面。,S7-200 PLC与MCGS组态五层电梯控制系统原理图及梯形图解析
一、项目简介 本项目是一套基于springBoot+mybatis+maven+vue夕阳红公寓管理系统 包含:项目源码、数据库脚本等,该项目附带全部源码可作为毕设使用。 项目都经过严格调试,eclipse或者idea 确保可以运行! 该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值 二、技术实现 jdk版本:1.8 及以上 ide工具:IDEA或者eclipse 数据库: mysql5.5及以上 后端:spring+springboot+mybatis+maven+mysql 前端: vue , css,js , elementui 三、系统功能 1、系统角色主要包括:管理员、用户 2、系统功能 主要功能包括: 用户登录注册 首页 个人中心 修改密码 个人信息 访客管理 公告信息管理 缴费管理 维修管理 行程轨迹管理 单页号类型管理 公告类型管理 维修类型管理 租客管理 轮播图管理 余额充值等功能 详见 https://flypeppa.blog.csdn.net/article/details/143117373
基于时空Transformer的端到端的视频注视目标检测.pdf
Online Retail.xlsx
,C#地磅称重无人值守管理软件。 软件实现功能: 1、身份证信息读取。 2、人证识别。 3、车牌识别(臻识摄像头、海康摄像头)。 4、LED显示屏文字输出。 5、称重仪数据。 6、二维码扫码。 7、语音播报。 8、红外对射功能。 9、道闸控制。
com.deepseek.chat.apk