costin      01/04/21 12:33:11

  Modified:    src/etc  server.xml
               src/share/org/apache/tomcat/modules/session
                        SessionIdGenerator.java
  Log:
  Fix server.xml with the right name of the attribute.
  
  Delay Random creation ( each random creates a thread )
  
  That concludes the fix of 1418, no hanging threads after shutdown.
  
  Note that shutdown/init is not completely debugged or tested - but at least there
  are no gross errors and kind-of works. In time things will improve ( the assumption
  is you don't do a soft restart every hour ).
  
  Soft restart is better in many cases - like when you embed tomcat in an application,
  as it doesn't require to restart the java vm and should clean up all the resources
  and return to a stable state.
  
  Of course, that requires that all modules respect the server state and clean
  up resources.
  
  Revision  Changes    Path
  1.74      +1 -6      jakarta-tomcat/src/etc/server.xml
  
  Index: server.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/etc/server.xml,v
  retrieving revision 1.73
  retrieving revision 1.74
  diff -u -r1.73 -r1.74
  --- server.xml        2001/04/21 17:45:40     1.73
  +++ server.xml        2001/04/21 19:33:10     1.74
  @@ -6,11 +6,6 @@
            will be used, and if not set "." will be used.
            webapps/, work/ and log/ will be relative to this ( unless 
            set explicitely to absolute paths ).
  -         You can also specify a "randomClass" attribute, which determines 
  -         a subclass of java.util.Random will be used for generating session IDs.
  -         By default this is "java.security.SecureRandom". 
  -         Specifying "java.util.Random" will speed up Tomcat startup, 
  -         but it will cause sessions to be less secure.
         -->
       <ContextManager debug="0" workDir="work" >
   
  @@ -41,7 +36,7 @@
           <SessionExpirer checkInterval="60" />
           <!-- For development you can use randomClass="java.util.Random" -->
           <SessionIdGenerator randomClass="java.security.SecureRandom" 
  -                            devRandom="/dev/urandom" />
  +                            randomFile="/dev/urandom" />
   
   
           <!-- ========== context processing modules ========== -->
  
  
  
  1.4       +19 -26    
jakarta-tomcat/src/share/org/apache/tomcat/modules/session/SessionIdGenerator.java
  
  Index: SessionIdGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/session/SessionIdGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SessionIdGenerator.java   2001/04/21 17:45:40     1.3
  +++ SessionIdGenerator.java   2001/04/21 19:33:11     1.4
  @@ -108,7 +108,6 @@
   
       public final void setRandomClass(String randomClass) {
        this.randomClassName=randomClass;
  -     randomSource=createRandomClass( randomClassName );
       }
   
       /** Use /dev/random-type special device. This is new code, but may reduce the
  @@ -157,15 +156,6 @@
       /** Init session management stuff for this context. 
        */
       public void engineInit(ContextManager cm) throws TomcatException {
  -     if( randomSource==null ) {
  -         // backward compatibility 
  -         String randomClass=(String)cm.getProperty("randomClass" );
  -         // set a reasonable default 
  -         if( randomClass==null ) {
  -             randomClass="java.security.SecureRandom";
  -         }
  -         setRandomClass(randomClass);
  -     }
       }
       
   
  @@ -207,24 +197,27 @@
        }           
       }    
   
  -    private Random createRandomClass( String s ) {
  -     Random randomSource=null;
  -     String className = s;
  -     if (className != null) {
  -         try {
  -             Class randomClass = Class.forName(className);
  -             long time=System.currentTimeMillis();
  -             randomSource = (java.util.Random)randomClass.newInstance();
  -             time = System.currentTimeMillis() - time;
  -             // Since this can take a lot of time, let the user know
  -             log( "Created random " + s + " in " + time );
  -         } catch (Exception e) {
  -             e.printStackTrace();
  +    /** Create the random generator using the configured class name, and
  +     * defaulting to java.security.SecureRandom
  +     */
  +    private void createRandomClass() {
  +     if( randomClassName==null ) {
  +         // backward compatibility 
  +         randomClassName=(String)cm.getProperty("randomClass" );
  +         // set a reasonable default 
  +         if( randomClassName==null ) {
  +             randomClassName="java.security.SecureRandom";
            }
        }
  +     try {
  +         Class randomClass = Class.forName(randomClassName);
  +         randomSource = (java.util.Random)randomClass.newInstance();
  +     } catch (Exception e) {
  +         log("SessionIdGenerator.createRandomClass", e);
  +     }
        if (randomSource == null)
            randomSource = new java.security.SecureRandom();
  -     return randomSource;
  +     log( "Created random class " + randomSource.getClass().getName());
       }
   
       /*
  @@ -265,8 +258,6 @@
       public synchronized String getIdentifier(String jsIdent)
       {
           StringBuffer sessionId = new StringBuffer();
  -     if( randomSource==null && randomIS==null)
  -         throw new RuntimeException( "No random source " );
        
           // random value ..
           long n = 0;
  @@ -281,6 +272,8 @@
            }
        }
        if( randomIS==null ) {
  +         if (randomSource==null )
  +             createRandomClass();
            n=randomSource.nextLong();
        } 
   
  
  
  

Reply via email to