public Connection getConnection() throws SQLException {
//int seconds = 0;
try{
if (closed)
throw new JGException("getConnection: Data source is closed");
int wc = 0;
cfc++;
if (cfc == 10)
{
cfc = 0;
checkForClosedConnections();
}
while (true) {
synchronized (cons)
{
if (!cons.isEmpty())
{
useCountAdd();
jiqlConnection connection = (jiqlConnection) cons.removeFirst();
connection.setClosed(false);
if (!connection.isClosed())
return connection;
else
{
if (debug)
System.out.println(new java.util.Date() + " Discarding Closed Pool Connection " + connectionsSize() + ":" + getUseCount() + ":" +getActiveCount() );
activeCountMinus();
checkForClosedConnections();
//createConnection();// 737:-717:20
}
}
}
if ( getActiveCount() < maxCount && creac < maxRC) {
Connection conn = createConnection();
useCountAdd();
return (conn);
}
else if (getActiveCount() >= maxCount)System.out.println("Excess jiqlDataSource Connection Objects: " + getActiveCount());
else if (creac >= maxRC)System.out.println("Excess jiqlDataSource Real Connections: " + creac);
try {
if (wc > loginTimeout)
throw new JGException("DB Login timeout OR too many open DB connections (" + getActiveCount() + ":" + creac + ":" + connectionsSize() + "). Please make sure your calling the close method in the Connection object.");
Thread.sleep(1000);
wc++;
} catch (InterruptedException e) {
;
}
}
// We have timed out awaiting an available connection
//throw new JGException
// ("getConnection: Timeout awaiting connection");
}catch (Throwable e){
org.jiql.util.JGUtil.olog(e);
e.printStackTrace();
throw new JGException
(e.toString());
}
}