User: patriot1burke
  Date: 01/08/08 15:05:34

  Modified:    src/main/org/jboss/test/threading/mbean Threads.java
  Log:
  added new testNonTransactional method to test non-transactional entity methods
  and locking
  
  Also, when stop is called, print out a message that thread is complete and
  how many threads are completed.  This is useful for figuring out if any
  threads are hung
  
  Revision  Changes    Path
  1.3       +123 -107  jbosstest/src/main/org/jboss/test/threading/mbean/Threads.java
  
  Index: Threads.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/threading/mbean/Threads.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Threads.java      2001/06/26 05:50:14     1.2
  +++ Threads.java      2001/08/08 22:05:33     1.3
  @@ -9,6 +9,7 @@
   import javax.naming.InitialContext;
   import org.jboss.test.threading.interfaces.EJBThreads;
   import org.jboss.test.threading.interfaces.EJBThreadsHome;
  +import java.rmi.RemoteException;
   
   import java.util.Random;
   
  @@ -18,7 +19,7 @@
   *
   *   @see <related>
   *   @author  <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  -*   @version $Revision: 1.2 $
  +*   @version $Revision: 1.3 $
   *   
   *   Revisions:
   *
  @@ -26,139 +27,154 @@
   */
   
   public class Threads
  -implements ThreadsMBean
  +   implements ThreadsMBean
   {
  -     // Constants -----------------------------------------------------
  +   // Constants -----------------------------------------------------
        
  -     // Attributes ----------------------------------------------------
  +   // Attributes ----------------------------------------------------
        
  -     private int numberOfThreads = 0;
  -     private int loops = 10;
  -     private long wait = 100;
  +   private int numberOfThreads = 0;
  +   private int loops = 10;
  +   private long wait = 100;
      public  boolean runMe = true;
  -     private Random random = new Random();
  +   private Random random = new Random();
  +   private Runnable test;
  +   private int threadsFinished = 0;
  +   // Static --------------------------------------------------------
        
  -     private Runnable test;
  -     // Static --------------------------------------------------------
  +   // Constructors --------------------------------------------------
        
  -     // Constructors --------------------------------------------------
  -     
        // Public --------------------------------------------------------
        
  -     public void setWait(long wait) {this.wait = wait;}
  -     public long getWait() {return wait;}
  +   public void setWait(long wait) {this.wait = wait;}
  +   public long getWait() {return wait;}
        
        
  -     public void setLoops(int loops) {this.loops = loops;}
  -     public int getLoops() {return loops;}
  +   public void setLoops(int loops) {this.loops = loops;}
  +   public int getLoops() {return loops;}
        
  -     public void setNumberOfThreads(int numberOfThreads) 
  -     {
  -             if (this.numberOfThreads > 0) stopMe();
  +   public void setNumberOfThreads(int numberOfThreads) 
  +   {
  +      if (this.numberOfThreads > 0) stopMe();
                        
  -             this.numberOfThreads=numberOfThreads;
  -             //restart
  -             try {
  -                             
  -                     if (numberOfThreads> 0) startMe();
  -             } 
  -             catch (Exception e) 
  -             {
  -                     e.printStackTrace();
  -             }
  -     }
  -     public int getNumberOfThreads() { return numberOfThreads;}
  -     
  -     public void startMe()
  -     throws Exception
  -     {
  -             runMe = true;
  -             
  -             if (numberOfThreads >0) {
  +      this.numberOfThreads=numberOfThreads;
  +      //restart
  +      try {
  +                             
  +         if (numberOfThreads> 0) startMe();
  +      } 
  +      catch (Exception e) 
  +      {
  +         e.printStackTrace();
  +      }
  +   }
  +   public int getNumberOfThreads() { return numberOfThreads;}
  +     
  +   public void startMe()
  +      throws Exception
  +   {
  +      runMe = true;
  +      threadsFinished = 0;
  +      if (numberOfThreads >0) {
                        
  -                     for (int i = 0; i < numberOfThreads ; i++) 
  -                     {
  -                             Thread t = new Thread(new Test());
  -                             System.out.println("started new thread " 
+t.hashCode());
  +         for (int i = 0; i < numberOfThreads ; i++) 
  +         {
  +            Thread t = new Thread(new Test());
  +            System.out.println("started new thread " +t.hashCode());
                                
  -                             t.start();
  +            t.start();
                        
  -                     };
  -             }
  -     }
  -     
  -     public void stopMe()
  -     {
  -             System.out.println("Stop called");
  -             runMe = false;
  -     };
  +         };
  +      }
  +   }
  +     
  +   public void stopMe()
  +   {
  +      System.out.println("Stop called");
  +      runMe = false;
  +   };
        
  -     public class Test implements Runnable {
  +   public class Test implements Runnable {
                
  -             public void run() {
  +      public void run() {
                        
  -                     try {
  +         try {
                                
  -                             InitialContext ic = new InitialContext();
  +            InitialContext ic = new InitialContext();
                                
  -                             EJBThreadsHome testHome = (EJBThreadsHome) 
ic.lookup("threads");
  +            EJBThreadsHome testHome = (EJBThreadsHome) ic.lookup("threads");
                                
  -                             EJBThreads ejbTest;
  -                             while(runMe) 
  -                             {
  +            EJBThreads ejbTest;
  +            while(runMe) 
  +            {
                                        
  -                                     ejbTest = null;
  +               ejbTest = null;
                                        
  -                                     try {
  +               try {
                                                
  -                                             ejbTest = 
testHome.findByPrimaryKey("test1");
  -                                     } 
  -                                     catch (Exception e) 
  -                                     {
  -                                             // Bean wasn't found create it 
  -                                             try {
  -                                                     ejbTest = 
testHome.create("test1");
  -                                             }
  +                  ejbTest = testHome.findByPrimaryKey("test1");
  +               } 
  +               catch (Exception e) 
  +               {
  +                  // Bean wasn't found create it 
  +                  try {
  +                     ejbTest = testHome.create("test1");
  +                  }
                                        
  -                                             catch (Exception e2) {}
  -                                     }
  +                  catch (Exception e2) 
  +                  {
  +                     System.out.println("****Create exception: " + e2);
  +                  }
  +               }
                                        
  -                                     if (ejbTest != null) try {
  +               if (ejbTest != null) try {
                                                
  -                                             // get a random value between 1 and 100
  -                                             int value = random.nextInt(100);
  +                  // get a random value between 1 and 100
  +                  int value = random.nextInt(100);
                                                
  -                                             // 10% removal
  -                                             if (value <10) {
  -                                                     ejbTest.remove();
  -                                             }
  -                                             // 40% normal
  -                                             else if (value<50) {
  -                                                     ejbTest.test();
  -                                             }
  -                                             // 20% business exception
  -                                             else if (value<70) {
  -                                                     
ejbTest.testBusinessException();
  -                                             }
  -                                             // 20 % runtime excpetion
  -                                             else if (value <90) {
  -                                                     ejbTest.testRuntimeException();
  -                                             }
  -                                             // 10% timeout
  -                                             else {
  -                                                     ejbTest.testTimeOut();
  -                                             }
  +                  // 10% removal
  +                  if (value <10) {
  +                     ejbTest.remove();
  +                  }
  +                  // 35% normal
  +                  else if (value<45) {
  +                     ejbTest.test();
  +                  }
  +                  // 15% business exception
  +                  else if (value<60) {
  +                     ejbTest.testBusinessException();
  +                  }
  +                  // 15 % runtime excpetion
  +                  else if (value <75) {
  +                     ejbTest.testRuntimeException();
  +                  }
  +                  // 15 % nonTransactional
  +                  else if (value <90) {
  +                     ejbTest.testNonTransactional();
  +                  }
  +                  // 10% timeout
  +                  else {
  +                     ejbTest.testTimeOut();
  +                  }
                                                
  -                                             synchronized (this) {
  -                                                     
//Thread.currentThread().yield();
  -                                                     wait(wait);
  -                                             }
  -                                     }catch (Exception e) {}
  -                             
  -                             }
  -                     }
  -                     catch (Exception e) {System.out.println("Exception for 
thread"+Thread.currentThread()); e.printStackTrace();}
  +                  synchronized (this) {
  +                     //Thread.currentThread().yield();
  +                     wait(wait);
  +                  }
  +               }
  +               catch (NullPointerException ignored) {}
  +               catch (RemoteException ignored) {}
  +               catch (Exception ex)
  +               {
  +                  System.out.println("***Exception thrown: " + ex);
  +               }
  +                             
  +            } // while(runMe)
  +            System.out.println(Thread.currentThread() + " is finished!!!!");
  +            System.out.println("Num threads finished is: " + ++threadsFinished);
  +         }
  +         catch (Exception e) {System.out.println("Exception for 
thread"+Thread.currentThread()); e.printStackTrace();}
                
  -             }
  -     }
  -}
  \ No newline at end of file
  +      }
  +   }
  +}
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to