CacheLib: better lock
authorNiki Roo <niki@nikiroo.be>
Fri, 1 May 2020 11:17:39 +0000 (13:17 +0200)
committerNiki Roo <niki@nikiroo.be>
Fri, 1 May 2020 11:17:39 +0000 (13:17 +0200)
src/be/nikiroo/fanfix/library/CacheLibrary.java

index 92e4ae7a9951ec9715dc5faa9271bae362412dbf..a3c3b5e3b7bb6f5a61962e8837158e28692feb56 100644 (file)
@@ -67,6 +67,7 @@ public class CacheLibrary extends BasicLibrary {
                        pg = new Progress();
                }
 
+               List<MetaData> copy;
                synchronized (metasLock) {
                        // We make sure that cached metas have precedence
                        if (metasMixed == null) {
@@ -86,10 +87,12 @@ public class CacheLibrary extends BasicLibrary {
                                        }
                                }
                        }
+
+                       copy = new ArrayList<MetaData>(metasMixed);
                }
 
                pg.done();
-               return new ArrayList<MetaData>(metasMixed);
+               return copy;
        }
 
        @Override
@@ -404,9 +407,7 @@ public class CacheLibrary extends BasicLibrary {
 
                MetaData meta = lib.imprt(url, pgImprt);
                updateMetaCache(metasReal, meta);
-               synchronized (metasLock) {
-                       metasMixed = null;
-               }
+               metasMixed = null;
 
                clearFromCache(meta.getLuid());