]> WPIA git - gigi.git/commitdiff
FIX: synchronization for IDCachable-Objects
authorFelix Dörre <felix@dogcraft.de>
Wed, 10 Sep 2014 17:46:37 +0000 (19:46 +0200)
committerFelix Dörre <felix@dogcraft.de>
Wed, 10 Sep 2014 20:29:45 +0000 (22:29 +0200)
Move synchronization blocks out so that it's garanteed that only one
instance exists per id.

src/org/cacert/gigi/dbObjects/Domain.java
src/org/cacert/gigi/dbObjects/DomainPingConfiguration.java
src/org/cacert/gigi/dbObjects/EmailAddress.java
src/org/cacert/gigi/dbObjects/User.java

index eb63b30b970283d6d0798d8f447a5326afa3ac65..3685de1b37fb2c68e77a76697d317730a9735be7 100644 (file)
@@ -222,13 +222,11 @@ public class Domain implements IdCachable {
 
     private static ObjectCache<Domain> myCache = new ObjectCache<>();
 
-    public static Domain getById(int id) throws IllegalArgumentException {
+    public static synchronized Domain getById(int id) throws IllegalArgumentException {
         Domain em = myCache.get(id);
         if (em == null) {
             try {
-                synchronized (Domain.class) {
-                    myCache.put(em = new Domain(id));
-                }
+                myCache.put(em = new Domain(id));
             } catch (SQLException e1) {
                 throw new IllegalArgumentException(e1);
             }
index 93eb363e2f9f1a57e9a6c926a459a5391a80f458..f5dd2a2c03cfda86ecca5be7b17aafd2e196fa71 100644 (file)
@@ -53,7 +53,7 @@ public class DomainPingConfiguration implements IdCachable {
 
     private static ObjectCache<DomainPingConfiguration> cache = new ObjectCache<>();
 
-    public static DomainPingConfiguration getById(int id) {
+    public static synchronized DomainPingConfiguration getById(int id) {
         DomainPingConfiguration res = cache.get(id);
         if (res == null) {
             try {
index 2acf59006e257f33fd7cf2f9bb493dbd05e23372..1191952f7e236ee93c1ab09fe8facfd3f8d5bfe5 100644 (file)
@@ -106,13 +106,11 @@ public class EmailAddress implements IdCachable {
 
     private static ObjectCache<EmailAddress> myCache = new ObjectCache<>();
 
-    public static EmailAddress getById(int id) throws IllegalArgumentException {
+    public static synchronized EmailAddress getById(int id) throws IllegalArgumentException {
         EmailAddress em = myCache.get(id);
         if (em == null) {
             try {
-                synchronized (EmailAddress.class) {
-                    myCache.put(em = new EmailAddress(id));
-                }
+                myCache.put(em = new EmailAddress(id));
             } catch (SQLException e1) {
                 throw new IllegalArgumentException(e1);
             }
index 7a11cdb40b9a294a568c8c934f6d277f2d02f93b..bc927fa9849bd647033fe8a50dfdf2baa7a4f645 100644 (file)
@@ -506,12 +506,10 @@ public class User implements IdCachable {
 
     private static ObjectCache<User> myCache = new ObjectCache<>();
 
-    public static User getById(int id) {
+    public static synchronized User getById(int id) {
         User u = myCache.get(id);
         if (u == null) {
-            synchronized (User.class) {
-                myCache.put(u = new User(id));
-            }
+            myCache.put(u = new User(id));
         }
         return u;
     }