From 0e28e66c07bffc3740ea3fefe54b4124c797249d Mon Sep 17 00:00:00 2001 From: Robin Kupper Date: Wed, 20 Apr 2011 00:42:21 +0200 Subject: [PATCH] Fixed connection pool not working at all --- src/de/diddiz/util/ConnectionPool.java | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/de/diddiz/util/ConnectionPool.java b/src/de/diddiz/util/ConnectionPool.java index b9d4659..fa52d36 100644 --- a/src/de/diddiz/util/ConnectionPool.java +++ b/src/de/diddiz/util/ConnectionPool.java @@ -77,14 +77,12 @@ public class ConnectionPool implements Driver { private class JDCConnection implements Connection { - private ConnectionService pool; private Connection conn; private boolean inuse; private long timestamp; - public JDCConnection(Connection conn, ConnectionService pool) { + public JDCConnection(Connection conn) { this.conn = conn; - this.pool = pool; this.inuse = false; this.timestamp = 0; } @@ -116,18 +114,14 @@ public class ConnectionPool implements Driver { return timestamp; } - public void close() throws SQLException { - pool.returnConnection(this); + public void close() { + expireLease(); } protected void expireLease() { inuse = false; } - protected Connection getConnection() { - return conn; - } - public PreparedStatement prepareStatement(String sql) throws SQLException { return conn.prepareStatement(sql); } @@ -393,15 +387,15 @@ public class ConnectionPool implements Driver { c = connections.elementAt(i); if (c.lease()) { if (c.validate()) - return c.getConnection(); + return c; else removeConnection(c); } } - c = new JDCConnection(DriverManager.getConnection(url, user, password), this); + c = new JDCConnection(DriverManager.getConnection(url, user, password)); c.lease(); connections.addElement(c); - return c.getConnection(); + return c; } public synchronized void returnConnection(JDCConnection conn) { @@ -423,8 +417,7 @@ public class ConnectionPool implements Driver { while (true) { try { Thread.sleep(delay); - } catch (InterruptedException e) { - } + } catch (InterruptedException e) {} pool.reapConnections(); } }