X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fdatabase%2FDatabaseConnection.java;h=1535ac3133a0e62865121c59a3a57952455aa9fb;hb=c3feb67ae28e66765dfcd2e7d50ddbceb64d92db;hp=43b7b748dd700809bb6d8a96f9a015e45e82cbd7;hpb=0ced2308e21d8295fb5de59de16bc56f1a5c00e2;p=gigi.git diff --git a/src/org/cacert/gigi/database/DatabaseConnection.java b/src/org/cacert/gigi/database/DatabaseConnection.java index 43b7b748..1535ac31 100644 --- a/src/org/cacert/gigi/database/DatabaseConnection.java +++ b/src/org/cacert/gigi/database/DatabaseConnection.java @@ -122,7 +122,7 @@ public class DatabaseConnection { } - public static final int CURRENT_SCHEMA_VERSION = 13; + public static final int CURRENT_SCHEMA_VERSION = 25; 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; + } }