X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fdatabase%2FDatabaseConnection.java;h=1535ac3133a0e62865121c59a3a57952455aa9fb;hb=c3feb67ae28e66765dfcd2e7d50ddbceb64d92db;hp=a855d706155faff34fd993cbbcbcf88fd0abb8c1;hpb=08f417851b48202af9f3a9b6254ac4d1c18262cb;p=gigi.git diff --git a/src/org/cacert/gigi/database/DatabaseConnection.java b/src/org/cacert/gigi/database/DatabaseConnection.java index a855d706..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 = 11; + 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; + } }