RFC - Reduce loading of PropertiesFile

Thomas Meyer thomas at m3y3r.de
Tue Apr 10 12:54:00 PDT 2012


diff -r 60ef5191add3 netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java
--- a/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java	Tue Apr 10 19:10:43 2012 +0200
+++ b/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java	Tue Apr 10 21:49:08 2012 +0200
@@ -108,11 +108,11 @@
      * Update map for keeping track of recently used items.
      */
     public synchronized void load() {
-        cacheOrder.load();
+        boolean loaded = cacheOrder.load();
         /* 
          * clean up possibly corrupted entries
          */
-        if (checkData()) {
+        if (loaded == true && checkData()) {
             if (JNLPRuntime.isDebug()) {
                 new LruCacheException().printStackTrace();
             }
@@ -125,7 +125,7 @@
     /**
      * check content of cacheOrder and remove invalid/corrupt entries
      *
-     * @return true, if cache was coruupted and affected entry removed
+     * @return true, if cache was corrupted and affected entry removed
      */
     private boolean checkData () {
         boolean modified = false;
diff -r 60ef5191add3 netx/net/sourceforge/jnlp/util/PropertiesFile.java
--- a/netx/net/sourceforge/jnlp/util/PropertiesFile.java	Tue Apr 10 19:10:43 2012 +0200
+++ b/netx/net/sourceforge/jnlp/util/PropertiesFile.java	Tue Apr 10 21:49:08 2012 +0200
@@ -35,6 +35,9 @@
 
     /** the header string */
     String header = "netx file";
+    
+    /** time of last modification */
+    long lastStore;
 
     /** lazy loaded on getProperty */
     boolean loaded = false;
@@ -104,24 +107,32 @@
      * Ensures that the file backing these properties has been
      * loaded; call this method before calling any method defined by
      * a superclass.
+     * 
+     * @return true, if file was (re-)loaded
+     *         false, if file was still current
      */
-    public void load() {
+    public boolean load() {
         loaded = true;
 
-        InputStream s = null;
-        try {
-            if (!file.exists())
-                return;
+        if(lastStore == 0 || lastStore > 0 && file.lastModified() != lastStore) {
+            InputStream s = null;
+            try {
+                if (!file.exists())
+                    return false;
+    
+                try {
+                    s = new FileInputStream(file);
+                    load(s);
+                } finally {
+                    if (s != null) s.close();
+                }
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+            return true;
+        }
 
-            try {
-                s = new FileInputStream(file);
-                load(s);
-            } finally {
-                if (s != null) s.close();
-            }
-        } catch (IOException ex) {
-            ex.printStackTrace();
-        }
+        return false;
     }
 
     /**
@@ -137,6 +148,7 @@
                 file.getParentFile().mkdirs();
                 s = new FileOutputStream(file);
                 store(s, header);
+                lastStore = file.lastModified();
             } finally {
                 if (s != null) s.close();
             }





More information about the distro-pkg-dev mailing list