Kommentar hinzugefügt
git-svn-id: https://svn.libreccm.org/ccm/trunk@884 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
3e139db6bb
commit
8267552268
|
|
@ -41,25 +41,21 @@ import org.apache.log4j.Logger;
|
|||
* @author Rafael H. Schloming <rhs@mit.edu>
|
||||
* @version $Id: PooledConnectionSource.java 885 2005-09-20 15:54:06Z sskracic $
|
||||
**/
|
||||
|
||||
public class PooledConnectionSource implements ConnectionSource {
|
||||
|
||||
private static final Logger s_log =
|
||||
Logger.getLogger(PooledConnectionSource.class);
|
||||
|
||||
private static CacheTable s_connectionTags =
|
||||
new CacheTable("jdbcConnectionTags",
|
||||
RuntimeConfig.getConfig().getJDBCPoolSize() + 10,
|
||||
CacheTable.MAX_CACHE_AGE,
|
||||
false);
|
||||
|
||||
private String m_url;
|
||||
private int m_size;
|
||||
private long m_interval;
|
||||
private Set m_connections = new HashSet();
|
||||
private List m_available = new ArrayList();
|
||||
private List m_untested = new ArrayList();
|
||||
|
||||
private static boolean s_taggingEnabled =
|
||||
RuntimeConfig.getConfig().isThreadTaggingEnabled();
|
||||
|
||||
|
|
@ -113,8 +109,9 @@ public class PooledConnectionSource implements ConnectionSource {
|
|||
renameThread(result);
|
||||
return result;
|
||||
} else {
|
||||
try { wait(); }
|
||||
catch (InterruptedException e) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new UncheckedWrapperException(e);
|
||||
}
|
||||
}
|
||||
|
|
@ -171,11 +168,9 @@ public class PooledConnectionSource implements ConnectionSource {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized void release(Connection conn) {
|
||||
if (!m_connections.contains(conn)) {
|
||||
throw new IllegalArgumentException
|
||||
("connection did come from ths source: " + conn);
|
||||
throw new IllegalArgumentException("connection did come from ths source: " + conn);
|
||||
}
|
||||
|
||||
boolean remove;
|
||||
|
|
@ -211,10 +206,13 @@ public class PooledConnectionSource implements ConnectionSource {
|
|||
}
|
||||
|
||||
private class Poller extends Thread {
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
try { Thread.sleep(m_interval); }
|
||||
catch (InterruptedException e) {
|
||||
s_log.error("PollerThread run(): " + m_interval);
|
||||
try {
|
||||
Thread.sleep(m_interval);
|
||||
} catch (InterruptedException e) {
|
||||
throw new UncheckedWrapperException(e);
|
||||
}
|
||||
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 {
|
||||
|
||||
public void run() {
|
||||
List untested = new ArrayList();
|
||||
while (true) {
|
||||
untested.clear();
|
||||
synchronized (m_untested) {
|
||||
if (m_untested.isEmpty()) {
|
||||
try { m_untested.wait(); }
|
||||
catch (InterruptedException e) {
|
||||
try {
|
||||
m_untested.wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new UncheckedWrapperException(e);
|
||||
}
|
||||
}
|
||||
|
|
@ -248,8 +250,7 @@ public class PooledConnectionSource implements ConnectionSource {
|
|||
try {
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
s_log.warn
|
||||
("error while closing bad connection", ex);
|
||||
s_log.warn("error while closing bad connection", ex);
|
||||
}
|
||||
}
|
||||
release(conn);
|
||||
|
|
@ -257,7 +258,6 @@ public class PooledConnectionSource implements ConnectionSource {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String[] TYPES = new String[]{"TABLE"};
|
||||
|
||||
private static SQLException test(Connection conn) {
|
||||
|
|
@ -272,5 +272,4 @@ public class PooledConnectionSource implements ConnectionSource {
|
|||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue