ceki        01/08/06 14:16:22

  Modified:    src/java/org/apache/log4j/helpers Loader.java
               src/java/org/apache/log4j/test MDCStress.java
  Log:
  - Improved MDCStress.java
  
  - changed method name in Loader.java
  
  Revision  Changes    Path
  1.13      +7 -1      jakarta-log4j/src/java/org/apache/log4j/helpers/Loader.java
  
  Index: Loader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/helpers/Loader.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Loader.java       2001/08/06 20:21:01     1.12
  +++ Loader.java       2001/08/06 21:16:22     1.13
  @@ -131,10 +131,16 @@
      */
     public
     static
  -  boolean java1() {
  +  boolean isJava1() {
       return java1;
     }
   
  +
  +  /**
  +     Load the specified class using the <code>Thread</code>
  +     <code>contextClassLoader</code> if running under Java2 or current
  +     class loader if running under JDK 1.1.
  +  */
     static
     public 
     Class loadClass (String clazz) throws ClassNotFoundException {
  
  
  
  1.4       +20 -16    jakarta-log4j/src/java/org/apache/log4j/test/MDCStress.java
  
  Index: MDCStress.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/test/MDCStress.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MDCStress.java    2001/08/06 19:40:29     1.3
  +++ MDCStress.java    2001/08/06 21:16:22     1.4
  @@ -18,13 +18,14 @@
   
     static int maxThreads;  
     static int threadCounter = 0;  
  +  static int totalThreads = 0;  
   
   
     public 
     static 
     void main(String args[]) {
       
  -    Layout layout = new PatternLayout("%r [%t] depth:%X{depth} - %m%n");
  +    Layout layout = new PatternLayout("%r [%t] depth=%X{depth} total=%X{total} - 
%m%n");
       Appender appender = new ConsoleAppender(layout);
       root.addAppender(appender);
   
  @@ -67,44 +68,47 @@
   
     public
     static
  -  void createChildren(int n, int depth) {
  +  void createChildren(int n, int currentDepth) {
       if (n <= 0)
         return;
   
       synchronized(MDCStress.class) {
         n = maxThreadsConstained(n);    
         for(int i = 0; i < n; i++) {
  -     new MDCStress(depth+1).start();
  +     threadCounter++;
  +     totalThreads++;
  +     log.debug("Creating Thread-"+(totalThreads-1));
  +     new MDCStress(currentDepth+1, totalThreads-1).start();
         }
       }
     }
   
   
     int depth;
  -  
  -  MDCStress(int depth) {
  +  int total;
  +
  +  MDCStress(int depth, int totalThreads) {
       this.depth = depth;
  +    this.total = totalThreads;
     }
   
     public
     void run() {
  -    MDC.put("depth", new Integer(depth));
       log.debug("Entered run()");
  -    
  -    int loopLength = randomInt(LOOP_LENGTH);
   
  -    int createIndex = loopLength/2;
  -    
  -    for(int i = 0; i <= loopLength; i++) {
  -      if(i==0) {
  -     createChildren(randomInt(BRANCHING_FACTOR), depth+1);
  -      }
  -    } 
  +    createChildren(randomInt(BRANCHING_FACTOR), depth);
  +
  +    MDC.put("depth", new Integer(depth));
  +    MDC.put("total", new Integer(this.total));
  +
  +    log.debug("Set MDC variables.");   
  +
  +    createChildren(randomInt(BRANCHING_FACTOR), depth);
       
   
       synchronized(MDCStress.class) {
         threadCounter--;
  -      root.debug( "Exiting run loop. " + threadCounter);
  +      root.debug("Exiting run loop. " + threadCounter);
         if(threadCounter <= 0) {
        MDCStress.class.notify(); // wake up the main thread
         }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to