Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4485321

java.util.prefs.Preferences.get() takes 1.5 seconds for non-existent preferences

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta
    • x86
    • windows_2000
    • Verified



      Name: bsC130419 Date: 07/27/2001


      C:\java>java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

      C:\java>

      Here's the test program:

      import java.util.prefs.*;

      public class Foo {

          public Foo() {
              long t1 = System.currentTimeMillis();
              Preferences preferences = Preferences.userNodeForPackage(this);
              long t2 = System.currentTimeMillis();
              String preference = preferences.get("somekey", "default");
              long t3 = System.currentTimeMillis();
              preferences.put("somekey", "value");
              long t4 = System.currentTimeMillis();
              preference = preferences.get("somekey", "default");
              long t5 = System.currentTimeMillis();
              try {
                  preferences.flush();
              } catch (BackingStoreException e) {
                  e.printStackTrace();
                  return;
              }
              long t6 = System.currentTimeMillis();
              preference = preferences.get("somekey", "default");
              long t7 = System.currentTimeMillis();
              preference = preferences.get("somekey", "default");
              long t8 = System.currentTimeMillis();
              preference = preferences.get("someOtherKey", "default");
              long t9 = System.currentTimeMillis();
              preference = preferences.get("someOtherKey", "default");
              long t10 = System.currentTimeMillis();
       
              System.out.println(t2 - t1 + "\t(userNodeForPackage)");
              System.out.println(t3 - t2 + "\t(get)");
              System.out.println(t4 - t3 + "\t(put)");
              System.out.println(t5 - t4 + "\t(get)");
              System.out.println(t6 - t5 + "\t(flush)");
              System.out.println(t7 - t6 + "\t(get)");
              System.out.println(t8 - t7 + "\t(get)");
              System.out.println(t9 - t8 + "\t(get)");
              System.out.println(t10 - t9 + "\t(get)");
          }

          public static void main(String[] args) {
              Foo f = new Foo();
          }
      }

      Here's the output from the first time it runs (without any preferences)...

      C:\java>java Foo
      60 (userNodeForPackage)
      1552 (get)
      0 (put)
      0 (get)
      250 (flush)
      0 (get)
      0 (get)
      1552 (get)
      1553 (get)

      C:\java>

      And here's the output from the second run (with the somekey preference now
      existing)...

      C:\java>java Foo
      60 (userNodeForPackage)
      0 (get)
      0 (put)
      0 (get)
      0 (flush)
      0 (get)
      0 (get)
      1552 (get)
      1552 (get)
      (Review ID: 128927)
      ======================================================================

            jjb Josh Bloch (Inactive)
            bstrathesunw Bill Strathearn (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: