X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fcacert%2Fgigi%2Fdatabase%2FDatabaseConnection.java;h=672dbe30e336c5f6d4479485115d484eeed8b488;hb=7689e5f2beef288a40be98470ae3be8452acf8b5;hp=80f96e8d68504701987761e129729561c013f82f;hpb=8f4a157d8a052486d019936ec499f02f912e1ddf;p=gigi.git diff --git a/src/org/cacert/gigi/database/DatabaseConnection.java b/src/org/cacert/gigi/database/DatabaseConnection.java index 80f96e8d..672dbe30 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 = 21; + 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; + } }