BlockingQueue<Connection> connections = new LinkedBlockingQueue<Connection>(maxConnection);
AtomicInteger numberOfDrewedConnectionFromPool
내 ConnectionPool에서 나는 LinkedBlockingQueue를 사용합니다. 곱하기 "if 문"이 스레드로부터 안전할지 여부에 대해서는 의심의 여지가 있습니다. maxConnection은 상수입니다. numberOfDrewedConnectionFromPool 잠금없이 방법 releaseConection도 변경() ..연결 풀
public Connection getConnection() throws ConnectionPoolException {
Connection connection = null;
if ((connections.poll() == null) && (maxConnection > numberOfDrewedConnectionFromPool.get())) {
return newConnection();
} else {
return connections.poll();
}
}
private Connection newConnection() throws ConnectionPoolException {
lock.lock();
Connection connection = null;
try {
try {
connection = DriverManager.getConnection(url, user, password);
numberOfDrewedConnectionFromPool.incrementAndGet();
} catch (SQLException exception) {
throw new ConnectionPoolException();
}
} finally {
lock.unlock();
return connection;
}
}
JB Nizet과 마찬가지로 http://sourceforge.net/projects/c3p0/와 같은 기존 연결 풀을 사용하십시오. 자신을 구현하는 것은 시간 낭비이고 불가능하지는 않더라도 어렵지 않습니다. – helpermethod
자신의 conectionPool은 작업의 요구 사항입니다) – Ivan
숙제입니까? 그렇지 않다면 상사에게 기존 연결 풀이 있는지, 그리고 연결 풀을 구현하려고 시도하면서 돈을 잃어 가고 있는지 설명하십시오. –