]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/database/DatabaseConnection.java
fix: deadlock possibility in "DatabaseConnection"
[gigi.git] / src / org / cacert / gigi / database / DatabaseConnection.java
index 0be7becdf90093ee8dddfd0693a77256656a9377..672dbe30e336c5f6d4479485115d484eeed8b488 100644 (file)
@@ -122,7 +122,7 @@ public class DatabaseConnection {
 
     }
 
-    public static final int CURRENT_SCHEMA_VERSION = 18;
+    public static final int CURRENT_SCHEMA_VERSION = 24;
 
     public static final int CONNECTION_TIMEOUT = 24 * 60 * 60;
 
@@ -344,22 +344,28 @@ public class DatabaseConnection {
         }
     }
 
-    public static synchronized Link newLink(boolean readOnly) throws InterruptedException {
-        if (instances.get(Thread.currentThread()) != null) {
-            throw new Error("There is already a connection allocated for this thread.");
-        }
-        if (pool.isEmpty() && connCount < 5) {
-            pool.addLast(new DatabaseConnection());
-            connCount++;
+    public static Link newLink(boolean readOnly) throws InterruptedException {
+        synchronized (DatabaseConnection.class) {
+
+            if (instances.get(Thread.currentThread()) != null) {
+                throw new Error("There is already a connection allocated for this thread.");
+            }
+            if (pool.isEmpty() && connCount < 5) {
+                pool.addLast(new DatabaseConnection());
+                connCount++;
+            }
         }
         DatabaseConnection conn = pool.takeFirst();
-        try {
-            conn.c.setReadOnly(readOnly);
-        } catch (SQLException e) {
-            throw new Error(e);
+        synchronized (DatabaseConnection.class) {
+            try {
+                conn.c.setReadOnly(readOnly);
+            } catch (SQLException e) {
+                throw new Error(e);
+            }
+            Link l = new Link(conn);
+            instances.put(Thread.currentThread(), l);
+            return l;
         }
-        Link l = new Link(conn);
-        instances.put(Thread.currentThread(), l);
-        return l;
+
     }
 }