- 浏览: 91244 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
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与连接池的整合...
sql server+java项目之科帮网计算机配件报价系统源代码
有java环境就可以运行起来 ,zip里包含源码+论文+PPT, 系统设计与功能: 文档详细描述了系统的后台管理功能,包括系统管理模块、新闻资讯管理模块、公告管理模块、社区影院管理模块、会员上传下载管理模块以及留言管理模块。 系统管理模块:允许管理员重新设置密码,记录登录日志,确保系统安全。 新闻资讯管理模块:实现新闻资讯的添加、删除、修改,确保主页新闻部分始终显示最新的文章。 公告管理模块:类似于新闻资讯管理,但专注于主页公告的后台管理。 社区影院管理模块:管理所有视频的添加、删除、修改,包括影片名、导演、主演、片长等信息。 会员上传下载管理模块:审核与删除会员上传的文件。 留言管理模块:回复与删除所有留言,确保系统内的留言得到及时处理。 环境说明: 开发语言:Java 框架:ssm,mybatis JDK版本:JDK1.8 数据库:mysql 5.7及以上 数据库工具:Navicat11及以上 开发软件:eclipse/idea Maven包:Maven3.3及以上
zip里包含源码+论文+PPT,有java环境就可以运行起来 ,功能说明: 文档开篇阐述了随着计算机技术、通信技术和网络技术的快速发展,智慧社区门户网站的建设成为了可能,并被视为21世纪信息产业的主要发展方向之一 强调了网络信息管理技术、数字化处理技术和数字式信息资源建设在国际竞争中的重要性。 指出了智慧社区门户网站系统的编程语言为Java,数据库为MYSQL,并实现了新闻资讯、社区共享、在线影院等功能。 系统设计与功能: 文档详细描述了系统的后台管理功能,包括系统管理模块、新闻资讯管理模块、公告管理模块、社区影院管理模块、会员上传下载管理模块以及留言管理模块。 系统管理模块:允许管理员重新设置密码,记录登录日志,确保系统安全。 新闻资讯管理模块:实现新闻资讯的添加、删除、修改,确保主页新闻部分始终显示最新的文章。 公告管理模块:类似于新闻资讯管理,但专注于主页公告的后台管理。 社区影院管理模块:管理所有视频的添加、删除、修改,包括影片名、导演、主演、片长等信息。 会员上传下载管理模块:审核与删除会员上传的文件。 留言管理模块:回复与删除所有留言,确保系统内的留言得到及时处理。
内容概要:本文档详细介绍了LinkLab实验的五个阶段,涵盖了ELF文件的组成、符号表的理解、代码节与重定位位置的修改等内容。每个阶段都有具体的实验要求和步骤,帮助学生理解链接的基本概念和链接过程中涉及的各项技术细节。 适合人群:计算机科学专业的本科生,特别是正在修读《计算机系统基础》课程的学生。 使用场景及目标:① 通过实际操作加深对链接过程和ELF文件的理解;② 掌握使用readelf、objdump和hexedit等工具的技巧;③ 实现特定输出以验证实验结果。 阅读建议:实验过程中的每个阶段都有明确的目标和提示,学生应按照步骤逐步操作,并结合反汇编代码和二进制编辑工具进行实践。在完成每个阶段的实验后,应及时记录实验结果和遇到的问题,以便于总结和反思。
【资源说明】 基于关键词的历时百度搜索指数自动采集资料齐全+详细文档+高分项目+源码.zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 3、本项目适合计算机相关专业(人工智能、通信工程、自动化、电子信息、物联网等)的在校学生、老师或者企业员工下载使用,也可作为毕业设计、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
第一次发文的小白,解释的不好,各位大佬勿怪哦
免费下载:Hilma af Klint a Biography (Julia Voss)_tFy2T.zip
屏幕截图 2024-12-21 172527
2024级涉外护理7班马天爱劳动实践总结1.docx
IndexOutOfBoundsException(解决方案)
有java环境就可以运行起来 ,zip里包含源码+论文+PPT, 系统设计与功能: 文档详细描述了系统的后台管理功能,包括系统管理模块、新闻资讯管理模块、公告管理模块、社区影院管理模块、会员上传下载管理模块以及留言管理模块。 系统管理模块:允许管理员重新设置密码,记录登录日志,确保系统安全。 新闻资讯管理模块:实现新闻资讯的添加、删除、修改,确保主页新闻部分始终显示最新的文章。 公告管理模块:类似于新闻资讯管理,但专注于主页公告的后台管理。 社区影院管理模块:管理所有视频的添加、删除、修改,包括影片名、导演、主演、片长等信息。 会员上传下载管理模块:审核与删除会员上传的文件。 留言管理模块:回复与删除所有留言,确保系统内的留言得到及时处理。 环境说明: 开发语言:Java 框架:ssm,mybatis JDK版本:JDK1.8 数据库:mysql 5.7及以上 数据库工具:Navicat11及以上 开发软件:eclipse/idea Maven包:Maven3.3及以上
有java环境就可以运行起来 ,zip里包含源码+论文+PPT, 系统设计与功能: 文档详细描述了系统的后台管理功能,包括系统管理模块、新闻资讯管理模块、公告管理模块、社区影院管理模块、会员上传下载管理模块以及留言管理模块。 系统管理模块:允许管理员重新设置密码,记录登录日志,确保系统安全。 新闻资讯管理模块:实现新闻资讯的添加、删除、修改,确保主页新闻部分始终显示最新的文章。 公告管理模块:类似于新闻资讯管理,但专注于主页公告的后台管理。 社区影院管理模块:管理所有视频的添加、删除、修改,包括影片名、导演、主演、片长等信息。 会员上传下载管理模块:审核与删除会员上传的文件。 留言管理模块:回复与删除所有留言,确保系统内的留言得到及时处理。 环境说明: 开发语言:Java 框架:ssm,mybatis JDK版本:JDK1.8 数据库:mysql 5.7及以上 数据库工具:Navicat11及以上 开发软件:eclipse/idea Maven包:Maven3.3及以上
zip里包含源码+论文+PPT,有java环境就可以运行起来 ,功能说明: 文档开篇阐述了随着计算机技术、通信技术和网络技术的快速发展,智慧社区门户网站的建设成为了可能,并被视为21世纪信息产业的主要发展方向之一 强调了网络信息管理技术、数字化处理技术和数字式信息资源建设在国际竞争中的重要性。 指出了智慧社区门户网站系统的编程语言为Java,数据库为MYSQL,并实现了新闻资讯、社区共享、在线影院等功能。 系统设计与功能: 文档详细描述了系统的后台管理功能,包括系统管理模块、新闻资讯管理模块、公告管理模块、社区影院管理模块、会员上传下载管理模块以及留言管理模块。 系统管理模块:允许管理员重新设置密码,记录登录日志,确保系统安全。 新闻资讯管理模块:实现新闻资讯的添加、删除、修改,确保主页新闻部分始终显示最新的文章。 公告管理模块:类似于新闻资讯管理,但专注于主页公告的后台管理。 社区影院管理模块:管理所有视频的添加、删除、修改,包括影片名、导演、主演、片长等信息。 会员上传下载管理模块:审核与删除会员上传的文件。 留言管理模块:回复与删除所有留言,确保系统内的留言得到及时处理。
DevExpressVCLProductDemos-24.2.3.exe
欢迎下载
有java环境就可以运行起来 ,zip里包含源码+论文+PPT, 系统设计与功能: 文档详细描述了系统的后台管理功能,包括系统管理模块、新闻资讯管理模块、公告管理模块、社区影院管理模块、会员上传下载管理模块以及留言管理模块。 系统管理模块:允许管理员重新设置密码,记录登录日志,确保系统安全。 新闻资讯管理模块:实现新闻资讯的添加、删除、修改,确保主页新闻部分始终显示最新的文章。 公告管理模块:类似于新闻资讯管理,但专注于主页公告的后台管理。 社区影院管理模块:管理所有视频的添加、删除、修改,包括影片名、导演、主演、片长等信息。 会员上传下载管理模块:审核与删除会员上传的文件。 留言管理模块:回复与删除所有留言,确保系统内的留言得到及时处理。 环境说明: 开发语言:Java 框架:ssm,mybatis JDK版本:JDK1.8 数据库:mysql 5.7及以上 数据库工具:Navicat11及以上 开发软件:eclipse/idea Maven包:Maven3.3及以上