Only in james-2.1.3: .classpath
Only in james-2.1.3: .project
Only in james-2.1.3: bin
Only in james-2.1.3/src/java/org/apache/james/util/mordred: #JdbcDataSource.java#
diff -dur james-2.1.3.orig/src/java/org/apache/james/util/mordred/JdbcDataSource.java james-2.1.3/src/java/org/apache/james/util/mordred/JdbcDataSource.java
--- james-2.1.3.orig/src/java/org/apache/james/util/mordred/JdbcDataSource.java	2003-05-07 05:02:00.000000000 +0200
+++ james-2.1.3/src/java/org/apache/james/util/mordred/JdbcDataSource.java	2004-04-13 16:49:11.179687500 +0200
@@ -109,6 +109,7 @@
                DataSourceComponent {
     // The limit that an active connection can be running
     public static final long ACTIVE_CONN_TIME_LIMIT = 60000; // (one minute)
+    public static final long ACTIVE_CONN_HARD_TIME_LIMIT = 60*60000; // (one hour)
     // How long before you kill off a connection due to inactivity
     public static final long CONN_IDLE_LIMIT        = 600000; // (10 minutes)
     private static final boolean DEEP_DEBUG         = false;
@@ -351,10 +352,12 @@
      *
      * @deprecated This was left over code from Town... but not exposed in Avalon.
      */
-    public synchronized void killAllConnections() {
-        //Just remove the references to all the connections... this will cause them to get
-        // finalized before very long. (not an instant shutdown, but that's ok).
-        pool.clear();
+    public void killAllConnections() {
+        synchronized (pool) {
+            //Just remove the references to all the connections... this will cause them to get
+            // finalized before very long. (not an instant shutdown, but that's ok).
+            pool.clear();
+        }
     }
 
     /**
@@ -432,42 +435,60 @@
     public void run() {
         try {
             while(reaperActive) {
-                for(int i = 0; i < pool.size(); i++) try {
-                    PoolConnEntry entry = (PoolConnEntry)pool.elementAt(i);
-                    long age            = System.currentTimeMillis() - entry.getLastActivity();
-                    synchronized(entry) {
-                        if((entry.getStatus() == PoolConnEntry.ACTIVE) &&
-                           (age > ACTIVE_CONN_TIME_LIMIT)) {
-                            StringBuffer logBuffer =
-                                new StringBuffer(128)
-                                        .append(" ***** connection ")
-                                        .append(entry.getId())
-                                        .append(" is way too old: ")
-                                        .append(age)
-                                        .append(" > ")
-                                        .append(ACTIVE_CONN_TIME_LIMIT);
-                            getLogger().info(logBuffer.toString());
-                            // This connection is way too old...
-                            // kill it no matter what
-                            finalizeEntry(entry);
-                            continue;
-                        }
-                        if((entry.getStatus() == PoolConnEntry.AVAILABLE) &&
-                           (age > CONN_IDLE_LIMIT)) {
-                            //We've got a connection that's too old... kill it
-                            finalizeEntry(entry);
-                            continue;
+                synchronized (pool) {
+                    for(int i = 0; i < pool.size(); i++) try {
+                        PoolConnEntry entry = (PoolConnEntry)pool.elementAt(i);
+                        long age            = System.currentTimeMillis() - entry.getLastActivity();
+                        synchronized(entry) {
+                            if((entry.getStatus() == PoolConnEntry.ACTIVE) &&
+                                    (age > ACTIVE_CONN_TIME_LIMIT)) {
+                                StringBuffer logBuffer =
+                                    new StringBuffer(128)
+                                    .append(" ***** connection ")
+                                    .append(entry.getId())
+                                    .append(" is way too old: ")
+                                    .append(age)
+                                    .append(" > ")
+                                    .append(ACTIVE_CONN_TIME_LIMIT);
+                                getLogger().info(logBuffer.toString());
+                                // This connection is way too old...
+                                // but don't kill a running connection:
+                                // finalizeEntry(entry);
+                                continue;
+                            }
+                            if((entry.getStatus() == PoolConnEntry.ACTIVE) &&
+                                    (age > ACTIVE_CONN_TIME_LIMIT)) {
+                                StringBuffer logBuffer =
+                                    new StringBuffer(128)
+                                    .append(" ***** connection ")
+                                    .append(entry.getId())
+                                    .append(" is long way too old: ")
+                                    .append(age)
+                                    .append(" > ")
+                                    .append(ACTIVE_CONN_HARD_TIME_LIMIT);
+                                getLogger().info(logBuffer.toString());
+                                // This connection is way too old...
+                                // have to kill a running connection:
+                                finalizeEntry(entry);
+                                continue;
+                            }
+                            if((entry.getStatus() == PoolConnEntry.AVAILABLE) &&
+                                    (age > CONN_IDLE_LIMIT)) {
+                                //We've got a connection that's too old... kill it
+                                finalizeEntry(entry);
+                                continue;
+                            }
                         }
                     }
-                }
-                catch (Throwable ex)
-                {
-                    StringWriter sout = new StringWriter();
-                    PrintWriter pout = new PrintWriter(sout, true);
-                    pout.println("Reaper Error: ");
-                    ex.printStackTrace(pout);
-                    if (getLogger().isErrorEnabled()) {
-                        getLogger().error(sout.toString());
+                    catch (Throwable ex)
+                    {
+                        StringWriter sout = new StringWriter();
+                        PrintWriter pout = new PrintWriter(sout, true);
+                        pout.println("Reaper Error: ");
+                        ex.printStackTrace(pout);
+                        if (getLogger().isErrorEnabled()) {
+                            getLogger().error(sout.toString());
+                        }
                     }
                 }
                 try {
@@ -504,7 +525,7 @@
      */
     private PoolConnEntry createConn() throws SQLException {
         PoolConnEntry entry = null;
-        synchronized(this) {
+        synchronized(pool) {
             if(connCreationsInProgress > 0) {
                 //We are already creating one in another place
                 return null;
@@ -560,7 +581,7 @@
             }
             return null;
         } finally {
-            synchronized(this) {
+            synchronized(pool) {
                 connCreationsInProgress--;
             }
         }
@@ -571,11 +592,13 @@
      *
      * @param entry entry
      */
-    private synchronized void finalizeEntry(PoolConnEntry entry) {
-        try {
-            entry.finalize();
-        } catch(Exception fe) {
+    private void finalizeEntry(PoolConnEntry entry) {
+        synchronized (pool) {
+            try {
+                entry.finalize();
+            } catch(Exception fe) {
+            }
+            pool.removeElement(entry);
         }
-        pool.removeElement(entry);
     }
 }

