Kommentar hinzugefügt

git-svn-id: https://svn.libreccm.org/ccm/trunk@884 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2011-04-30 19:46:07 +00:00
parent 3e139db6bb
commit 8267552268
1 changed files with 33 additions and 34 deletions

View File

@ -41,25 +41,21 @@ import org.apache.log4j.Logger;
* @author Rafael H. Schloming <rhs@mit.edu> * @author Rafael H. Schloming <rhs@mit.edu>
* @version $Id: PooledConnectionSource.java 885 2005-09-20 15:54:06Z sskracic $ * @version $Id: PooledConnectionSource.java 885 2005-09-20 15:54:06Z sskracic $
**/ **/
public class PooledConnectionSource implements ConnectionSource { public class PooledConnectionSource implements ConnectionSource {
private static final Logger s_log = private static final Logger s_log =
Logger.getLogger(PooledConnectionSource.class); Logger.getLogger(PooledConnectionSource.class);
private static CacheTable s_connectionTags = private static CacheTable s_connectionTags =
new CacheTable("jdbcConnectionTags", new CacheTable("jdbcConnectionTags",
RuntimeConfig.getConfig().getJDBCPoolSize() + 10, RuntimeConfig.getConfig().getJDBCPoolSize() + 10,
CacheTable.MAX_CACHE_AGE, CacheTable.MAX_CACHE_AGE,
false); false);
private String m_url; private String m_url;
private int m_size; private int m_size;
private long m_interval; private long m_interval;
private Set m_connections = new HashSet(); private Set m_connections = new HashSet();
private List m_available = new ArrayList(); private List m_available = new ArrayList();
private List m_untested = new ArrayList(); private List m_untested = new ArrayList();
private static boolean s_taggingEnabled = private static boolean s_taggingEnabled =
RuntimeConfig.getConfig().isThreadTaggingEnabled(); RuntimeConfig.getConfig().isThreadTaggingEnabled();
@ -113,8 +109,9 @@ public class PooledConnectionSource implements ConnectionSource {
renameThread(result); renameThread(result);
return result; return result;
} else { } else {
try { wait(); } try {
catch (InterruptedException e) { wait();
} catch (InterruptedException e) {
throw new UncheckedWrapperException(e); throw new UncheckedWrapperException(e);
} }
} }
@ -171,11 +168,9 @@ public class PooledConnectionSource implements ConnectionSource {
} }
} }
public synchronized void release(Connection conn) { public synchronized void release(Connection conn) {
if (!m_connections.contains(conn)) { if (!m_connections.contains(conn)) {
throw new IllegalArgumentException throw new IllegalArgumentException("connection did come from ths source: " + conn);
("connection did come from ths source: " + conn);
} }
boolean remove; boolean remove;
@ -211,10 +206,13 @@ public class PooledConnectionSource implements ConnectionSource {
} }
private class Poller extends Thread { private class Poller extends Thread {
public void run() { public void run() {
while (true) { while (true) {
try { Thread.sleep(m_interval); } s_log.error("PollerThread run(): " + m_interval);
catch (InterruptedException e) { try {
Thread.sleep(m_interval);
} catch (InterruptedException e) {
throw new UncheckedWrapperException(e); throw new UncheckedWrapperException(e);
} }
testAvailable(); testAvailable();
@ -222,15 +220,19 @@ public class PooledConnectionSource implements ConnectionSource {
} }
} }
// This Thread is running only if ther Poller Thread sends a notify() to
// the synchronized m_untested variable.
private class Tester extends Thread { private class Tester extends Thread {
public void run() { public void run() {
List untested = new ArrayList(); List untested = new ArrayList();
while (true) { while (true) {
untested.clear(); untested.clear();
synchronized (m_untested) { synchronized (m_untested) {
if (m_untested.isEmpty()) { if (m_untested.isEmpty()) {
try { m_untested.wait(); } try {
catch (InterruptedException e) { m_untested.wait();
} catch (InterruptedException e) {
throw new UncheckedWrapperException(e); throw new UncheckedWrapperException(e);
} }
} }
@ -248,8 +250,7 @@ public class PooledConnectionSource implements ConnectionSource {
try { try {
conn.close(); conn.close();
} catch (SQLException ex) { } catch (SQLException ex) {
s_log.warn s_log.warn("error while closing bad connection", ex);
("error while closing bad connection", ex);
} }
} }
release(conn); release(conn);
@ -257,7 +258,6 @@ public class PooledConnectionSource implements ConnectionSource {
} }
} }
} }
private static final String[] TYPES = new String[]{"TABLE"}; private static final String[] TYPES = new String[]{"TABLE"};
private static SQLException test(Connection conn) { private static SQLException test(Connection conn) {
@ -272,5 +272,4 @@ public class PooledConnectionSource implements ConnectionSource {
return e; return e;
} }
} }
} }