manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1336728 - in /incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool: ConnectionPool.java ConnectionPoolManager.java
Date Thu, 10 May 2012 14:56:41 GMT
Author: kwright
Date: Thu May 10 14:56:41 2012
New Revision: 1336728

URL: http://svn.apache.org/viewvc?rev=1336728&view=rev
Log:
Fix deadlock on shutdown.

Modified:
    incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPool.java
    incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java

Modified: incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPool.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPool.java?rev=1336728&r1=1336727&r2=1336728&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPool.java
(original)
+++ incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPool.java
Thu May 10 14:56:41 2012
@@ -115,6 +115,7 @@ public class ConnectionPool
       }
       freeConnections[i] = null;
     }
+    freePointer = 0;
   }
   
   /** Clean up expired connections.

Modified: incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java?rev=1336728&r1=1336727&r2=1336728&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java
(original)
+++ incubator/lcf/branches/CONNECTORS-96/framework/core/src/main/java/org/apache/manifoldcf/core/jdbcpool/ConnectionPoolManager.java
Thu May 10 14:56:41 2012
@@ -31,7 +31,7 @@ public class ConnectionPoolManager
 
   protected Map<String,ConnectionPool> poolMap;
   protected ConnectionCloserThread connectionCloserThread;
-  protected AtomicBoolean shuttingDown = new AtomicBoolean(false);
+  protected volatile AtomicBoolean shuttingDown = new AtomicBoolean(false);
 
   public ConnectionPoolManager(int count)
   {
@@ -59,7 +59,7 @@ public class ConnectionPoolManager
     return cp;
   }
   
-  public synchronized void shutdown()
+  public void shutdown()
   {
     shuttingDown.set(true);
     while (connectionCloserThread.isAlive())
@@ -74,23 +74,35 @@ public class ConnectionPoolManager
         connectionCloserThread.interrupt();
       }
     }
-    Iterator<String> iter = poolMap.keySet().iterator();
-    while (iter.hasNext())
+    synchronized (this)
     {
-      String poolKey = iter.next();
-      ConnectionPool cp = poolMap.get(poolKey);
-      cp.closePool();
+      Iterator<String> iter = poolMap.keySet().iterator();
+      while (iter.hasNext())
+      {
+        String poolKey = iter.next();
+        ConnectionPool cp = poolMap.get(poolKey);
+        cp.closePool();
+      }
     }
   }
   
-  protected synchronized void cleanupExpiredConnections(long cleanupTime)
+  protected void cleanupExpiredConnections(long cleanupTime)
   {
-    Iterator<String> iter = poolMap.keySet().iterator();
-    while (iter.hasNext())
+    ConnectionPool[] connectionPools;
+    synchronized (this)
+    {
+      connectionPools = new ConnectionPool[poolMap.size()];
+      int i = 0;
+      Iterator<String> iter = poolMap.keySet().iterator();
+      while (iter.hasNext())
+      {
+        String poolKey = iter.next();
+        connectionPools[i++] = poolMap.get(poolKey);
+      }
+    }
+    for (int i = 0 ; i < connectionPools.length ; i++)
     {
-      String poolKey = iter.next();
-      ConnectionPool cp = poolMap.get(poolKey);
-      cp.cleanupExpiredConnections(cleanupTime);
+      connectionPools[i].cleanupExpiredConnections(cleanupTime);
     }
   }
   
@@ -108,12 +120,14 @@ public class ConnectionPoolManager
     {
       while (true)
       {
+        if (shuttingDown.get())
+          break;
         cleanupExpiredConnections(System.currentTimeMillis());
         if (shuttingDown.get())
           break;
         try
         {
-          Thread.sleep(60000L);
+          Thread.sleep(5000L);
         }
         catch (InterruptedException e)
         {



Mime
View raw message