Attached are patches to StandardManager.java and SessionIdGenerator.java.
These changes cause the PRNG used to generate session ids to be initialized
when a context is initialized instead of when the first session id is
generated.  The PRNG used by default in 3.2 (java.security.SecureRandom)
takes a rather long time to return its first random number (about 10-15
seconds on my hardware).  I think it makes more sense for the time consuming
initialization stuff to happen when TC starts rather then when requests are
being handled.
Index: StandardManager.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/session/Attic/StandardManager.java,v
retrieving revision 1.11.2.1
diff -u -r1.11.2.1 StandardManager.java
--- StandardManager.java        2000/11/18 01:33:59     1.11.2.1
+++ StandardManager.java        2000/12/11 20:35:09
@@ -165,6 +165,7 @@
     // ------------------------------------------------------------- Constructor
 
     public StandardManager() {
+                SessionIdGenerator.initialize();
     }
 
     // ------------------------------------------------------------- Properties
Index: SessionIdGenerator.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/util/SessionIdGenerator.java,v
retrieving revision 1.3.2.2
diff -u -r1.3.2.2 SessionIdGenerator.java
--- SessionIdGenerator.java     2000/11/18 01:33:59     1.3.2.2
+++ SessionIdGenerator.java     2000/12/11 20:34:06
@@ -114,11 +114,37 @@
      */
     public final static long ticDifference = 2000;
 
-    // ** NOTE that this must work together with get_jserv_session_balance()
+        /*
+         * Loads the random number generator and gets a random long.  This
+         * causes any initialization code for the PRNG to be executed.  This
+         * prevents possibly long running code from being executed when the
+         * first session is created.
+         */
+        public static void initialize()
+        {
+                if (randomSource == null) {
+                         String className = 
+System.getProperty("tomcat.sessionid.randomclass");
+                         if (className != null) {
+                                       try {
+                                                Class randomClass = 
+Class.forName(className);
+                                                randomSource = 
+(java.util.Random)randomClass.newInstance();
+                                       }
+                                       catch (Exception e) {
+                                                e.printStackTrace();
+                                       }
+                         }
+                         if (randomSource == null)
+                                       randomSource = new 
+java.security.SecureRandom();
+                }
+
+                randomSource.nextLong();
+        }
+
+        // ** NOTE that this must work together with get_jserv_session_balance()
     // ** in jserv_balance.c
     static synchronized public String getIdentifier (String jsIdent)
     {
-        StringBuffer sessionId = new StringBuffer();
+                 StringBuffer sessionId = new StringBuffer();
         
         if (randomSource == null) {
             String className = System.getProperty("tomcat.sessionid.randomclass");

Reply via email to