jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1025505 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/SeededSecureRandom.java
Date Wed, 20 Oct 2010 11:25:29 GMT
Author: thomasm
Date: Wed Oct 20 11:25:29 2010
New Revision: 1025505

URL: http://svn.apache.org/viewvc?rev=1025505&view=rev
Log:
JCR-2795 Initializing SeededSecureRandom may be slow

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/SeededSecureRandom.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/SeededSecureRandom.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/SeededSecureRandom.java?rev=1025505&r1=1025504&r2=1025505&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/SeededSecureRandom.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/SeededSecureRandom.java
Wed Oct 20 11:25:29 2010
@@ -45,7 +45,11 @@ class SeededSecureRandom extends SecureR
      */
     public static Random getInstance() {
         if (instance == null) {
-            instance = new SeededSecureRandom();
+            synchronized (SeededSecureRandom.class) {
+                if (instance == null) {
+                    instance = new SeededSecureRandom();
+                }
+            }
         }
         return instance;
     }
@@ -72,6 +76,14 @@ class SeededSecureRandom extends SecureR
         if (!seeded) {
             // Alternative seed algorithm if the default is very slow
             setSeed(System.currentTimeMillis());
+            setSeed(System.nanoTime());
+            setSeed(new Object().hashCode());
+            Runtime runtime = Runtime.getRuntime();
+            setSeed(runtime.freeMemory());
+            setSeed(runtime.maxMemory());
+            setSeed(runtime.totalMemory());
+            setSeed(System.getProperties().toString().hashCode());
+
             // Thread timing (a second thread is already running)
             for (int j = 0; j < 16; j++) {
                 int i = 0;



Mime
View raw message