- 浏览: 91990 次
- 性别:
- 来自: 上海
-
文章分类
最新评论
-
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与连接池的整合...
一、项目简介 包含:项目源码、数据库脚本等,该项目附带全部源码可作为毕设使用。 项目都经过严格调试,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/146122666
项目已获导师指导并通过的高分毕业设计项目,可作为课程设计和期末大作业,下载即用无需修改,项目完整确保可以运行。 包含:项目源码、数据库脚本、软件工具等,该项目可以作为毕设、课程设计使用,前后端代码都在里面。 该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。 项目都经过严格调试,确保可以运行!可以放心下载 技术组成 语言:java 开发环境:idea 数据库:MySql 部署环境:maven 数据库工具:navica 更多毕业设计https://cv2022.blog.csdn.net/article/details/124463185
内容为Python程序设计的思维导图,适用于新手小白进行浏览,理清思路
2024-Stable Diffusion全套资料(软件+关键词+模型).rar
mmexport1741417035005.png
COMSOL三维锂离子电池全耦合电化学热应力模型:模拟充放电过程中的多物理场耦合效应及电芯内应力应变情况,COMSOL锂离子电池热应力全耦合模型,comsol三维锂离子电池电化学热应力全耦合模型锂离子电池耦合COMSOL固体力学模块和固体传热模块,模型仿真模拟电池在充放电过程中由于锂插层,热膨胀以及外部约束所导致的电极的应力应变情况结果有电芯中集流体,电极,隔膜的应力应变以及压力情况等,电化学-力单向耦合和双向耦合 ,关键词: 1. COMSOL三维锂离子电池模型; 2. 电化学热应力全耦合模型; 3. 锂离子电池; 4. 固体力学模块; 5. 固体传热模块; 6. 应力应变情况; 7. 电芯中集流体; 8. 电极; 9. 隔膜; 10. 电化学-力单向/双向耦合。,COMSOL锂离子电池全耦合热应力仿真模型
基于传递矩阵法的一维层状声子晶体振动传输特性及其优化设计与应用,声子晶体传递矩阵法解析及应用,Matlab 一维层状声子晶体振动传输特性 传递矩阵法在声子晶体的设计和应用中具有重要作用。 通过调整声子晶体的材料、周期和晶格常数等参数,可以设计出具有特定带隙结构的声子晶体,用于滤波、减震、降噪等应用。 例如,通过调整声子晶体的周期数和晶格常数,可以改变带隙的位置和宽度,从而实现特定的频率范围内的噪声控制。 此外,传递矩阵法还可以用于分析和优化声子晶体的透射谱,为声学器件的设计提供理论依据。 ,Matlab; 一维层状声子晶体; 振动传输特性; 传递矩阵法; 材料调整; 周期和晶格常数; 带隙结构; 滤波; 减震; 降噪; 透射谱分析; 声学器件设计,Matlab模拟声子晶体振动传输特性及优化设计研究
头部姿态估计(HeadPose Estimation)-Android源码
永磁同步电机FOC、MPC与高频注入Simulink模型及基于MBD的代码生成工具,适用于Ti f28335与dspace/ccs平台开发,含电机控制开发文档,永磁同步电机控制技术:FOC、MPC与高频注入Simulink模型开发及应用指南,提供永磁同步电机FOC,MPC,高频注入simulink模型。 提供基于模型开发(MBD)代码生成模型,可结合Ti f28335进行电机模型快速开发,可适用dspace平台或者ccs平台。 提供电机控制开发编码器,转子位置定向,pid调试相关文档。 ,永磁同步电机; FOC控制; MPC控制; 高频注入; Simulink模型; 模型开发(MBD); Ti f28335; 电机模型开发; dspace平台; ccs平台; 编码器; 转子位置定向; pid调试。,永磁同步电机MPC-FOC控制与代码生成模型
light of warehouse.zip
内容概要:文章深入讨论了工业乙醇发酵的基本原理及工艺流程,特别是在温度和气体排放(如CO2及其他有害气体)影响下的发酵效果分析。文章介绍了乙醇发酵的重要环节,如糖分解、代谢路径、代谢调控以及各阶段的操作流程,重点展示了如何通过Matlab建模和仿真实验来探索这两个关键环境因素对发酵过程的具体影响。通过动态模型仿真分析,得出合适的温度范围以及适时排除CO2能显著提升发酵产乙醇的效果与效率,从而提出了基于仿真的优化发酵生产工艺的新方法。 适用人群:从事生物工程相关领域研究的科学家、工程师及相关专业师生。 使用场景及目标:适用于实验室环境、学术交流会议及实际生产指导中,以提升研究人员对该领域内复杂现象的理解能力和技术水平为目标。 其他说明:附录中有详细的数学公式表达和程序代码可供下载执行,便于有兴趣的研究团队重复实验或者继续扩展研究工作。
本资源包专为解决 Tomcat 启动时提示「CATALINA_HOME 环境变量未正确配置」问题而整理,包含以下内容: 1. **Apache Tomcat 9.0.69 官方安装包**:已验证兼容性,解压即用。 2. **环境变量配置指南**: - Windows 系统下 `CATALINA_HOME` 和 `JAVA_HOME` 的详细配置步骤。 - 常见错误排查方法(如路径含空格、未生效问题)。 3. **辅助工具脚本**:一键检测环境变量是否生效的批处理文件。 4. **解决方案文档**:图文并茂的 PDF 文档,涵盖从报错分析到成功启动的全流程。 适用场景: - Tomcat 9.x 版本环境配置 - Java Web 开发环境搭建 - 运维部署调试 注意事项: - 资源包路径需为纯英文,避免特殊字符。 - 建议使用 JDK 8 或更高版本。
这是一款仿照京东商城的Java Web项目源码,完美复现了360buy的用户界面和购物流程,非常适合Java初学者和开发者进行学习与实践。通过这份源码,你将深入了解电商平台的架构设计和实现方法。欢迎大家下载体验,提升自己的编程能力!
系统选用B/S模式,后端应用springboot框架,前端应用vue框架, MySQL为后台数据库。 本系统基于java设计的各项功能,数据库服务器端采用了Mysql作为后台数据库,使Web与数据库紧密联系起来。 在设计过程中,充分保证了系统代码的良好可读性、实用性、易扩展性、通用性、便于后期维护、操作方便以及页面简洁等特点。
这是一款专为大学生打造的求职就业网JavaWeb毕业设计源码,功能齐全,界面友好。它提供简历投递、职位搜索、在线交流等多种实用功能,能够帮助你顺利进入职场。无论你是想提升技术水平还是寻找灵感,这个源码都是不可多得的资源。快来下载,让你的求职之路更加顺畅吧!
useTable(1).ts