sebb        2004/10/12 16:45:21

  Modified:    src/core/org/apache/jmeter/engine Tag: rel-2_0
                        StandardJMeterEngine.java
  Log:
  Bug 30110 - deadlock in stop test
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.43.2.8  +36 -10    
jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java
  
  Index: StandardJMeterEngine.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java,v
  retrieving revision 1.43.2.7
  retrieving revision 1.43.2.8
  diff -u -r1.43.2.7 -r1.43.2.8
  --- StandardJMeterEngine.java 11 Oct 2004 00:16:53 -0000      1.43.2.7
  +++ StandardJMeterEngine.java 12 Oct 2004 23:45:21 -0000      1.43.2.8
  @@ -75,12 +75,12 @@
       public static void stopEngineNow()
       {
        if (engine != null) // May be null if called from Unit test
  -       engine.stopTest();
  +       engine.stopTest(true);
       }
       public static void stopEngine()
       {
        if (engine != null)  // May be null if called from Unit test
  -       engine.askThreadsToStop();
  +             engine.stopTest(false);
       }
       public static boolean stopThread(String threadName)
       {
  @@ -277,22 +277,46 @@
           stopThread.start();
       }
   
  +    public synchronized void stopTest(boolean b)
  +    {
  +        Thread stopThread = new Thread(new StopTest(b));
  +        stopThread.start();
  +    }
  +    
  +    public void askThreadsToStop()
  +    {
  +     engine.stopTest(false);
  +    }
  +    
       private class StopTest implements Runnable
       {
  +     boolean now;
  +     private StopTest(){
  +             now=true;
  +     }
  +     private StopTest(boolean b){
  +             now=b;
  +     }
           public void run()
           {
               if (running)
               {
                   running = false;
  -                tellThreadsToStop();
  +                if (now){
  +                     tellThreadsToStop();
  +                } else {
  +                     stopAllThreads();
  +                }
                   try
                   {
                       Thread.sleep(10 * allThreads.size());
                   }
                   catch (InterruptedException e)
                   {}
  -                verifyThreadsStopped();
  -                notifyTestListenersOfEnd();
  +                boolean stopped=verifyThreadsStopped();
  +                if (stopped || now){
  +                    notifyTestListenersOfEnd();
  +                }
               }
           }
       }
  @@ -463,8 +487,9 @@
           }
       }
   
  -    private void verifyThreadsStopped()
  +    private boolean verifyThreadsStopped()
       {
  +     boolean stoppedAll=true;
           Iterator iter = new HashSet(allThreads.keySet()).iterator();
           while (iter.hasNext())
           {
  @@ -479,10 +504,12 @@
                   {}
                   if (t.isAlive())
                   {
  +                     stoppedAll=false;
                       log.info("Thread won't die: " + t.getName());
                   }
               }
           }
  +        return stoppedAll;
       }
   
       private void tellThreadsToStop()
  @@ -505,7 +532,7 @@
           }
       }
       
  -     public void askThreadsToStop()
  +     private void stopAllThreads()
        {
                Iterator iter = new HashSet(allThreads.keySet()).iterator();
                while (iter.hasNext())
  @@ -513,7 +540,6 @@
                        JMeterThread item = (JMeterThread) iter.next();
                        item.stop();
                }
  -             verifyThreadsStopped();
        }
   
       // Remote exit
  
  
  

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

Reply via email to