org.apache.jmeter.threads

## Class AbstractThreadGroup

- java.lang.Object
- - org.apache.jmeter.testelement.AbstractTestElement
  - - org.apache.jmeter.threads.AbstractThreadGroup

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Controller, Searchable, TestElement, JMeterThreadMonitor, TestCompilerHelper
  Direct Known Subclasses:
    ThreadGroup

      public abstract class AbstractThreadGroup
      extends AbstractTestElement
      implements java.io.Serializable, Controller, JMeterThreadMonitor, TestCompilerHelper

  ThreadGroup holds the settings for a JMeter thread group. This class is intended to be ThreadSafe.
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `MAIN_CONTROLLER`
    `static java.lang.String` | `NUM_THREADS` Number of threads in the thread group
    `static java.lang.String` | `ON_SAMPLE_ERROR` Action to be taken when a Sampler error occurs
    `static java.lang.String` | `ON_SAMPLE_ERROR_CONTINUE` Continue, i.e. ignore sampler errors
    `static java.lang.String` | `ON_SAMPLE_ERROR_START_NEXT_LOOP` Start next loop for current thread if sampler error occurs
    `static java.lang.String` | `ON_SAMPLE_ERROR_STOPTEST` Stop test (all threads) if sampler error occurs, the entire test is stopped at the end of any current samples
    `static java.lang.String` | `ON_SAMPLE_ERROR_STOPTEST_NOW` Stop test NOW (all threads) if sampler error occurs, the entire test is stopped abruptly.
    `static java.lang.String` | `ON_SAMPLE_ERROR_STOPTHREAD` Stop current thread if sampler error occurs

    - ### Fields inherited from interface org.apache.jmeter.testelement.TestElement

      `COMMENTS, ENABLED, GUI_CLASS, NAME, TEST_CLASS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractThreadGroup()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addIterationListener(LoopIterationListener lis)` Controllers have to notify listeners of when they begin an iteration through their sub-elements.
    `abstract JMeterThread` | `addNewThread(int delay, StandardJMeterEngine engine)` Add a new `JMeterThread` to this `ThreadGroup` for engine
    `void` | `addTestElement(TestElement child)` Add a test element.
    `boolean` | `addTestElementOnce(TestElement child)` Add child test element only if it has not already been added.
    `void` | `breakThreadLoop()`
    `int` | `getNumberOfThreads()` Get the number of active threads
    `int` | `getNumThreads()` Get the number of threads.
    `boolean` | `getOnErrorStartNextLoop()` Check if a sampler error should cause thread to start next loop.
    `boolean` | `getOnErrorStopTest()` Check if a sampler error should cause test to stop.
    `boolean` | `getOnErrorStopTestNow()` Check if a sampler error should cause test to stop now.
    `boolean` | `getOnErrorStopThread()` Check if a sampler error should cause thread to stop.
    `Controller` | `getSamplerController()` Get the sampler controller.
    `void` | `initialize()` Called to initialize a controller at the beginning of a test iteration.
    `boolean` | `isDone()` Indicates whether the Controller is done delivering Samplers for the rest of the test.
    `Sampler` | `next()` Delivers the next Sampler or null
    `abstract int` | `numberOfActiveThreads()`
    `void` | `removeIterationListener(LoopIterationListener iterationListener)` Unregister IterationListener
    `void` | `setNumThreads(int numThreads)` Set the total number of threads to start
    `void` | `setSamplerController(LoopController c)` Set the sampler controller.
    `abstract void` | `start(int groupCount, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine)` Start the `ThreadGroup`
    `void` | `startNextLoop()` Start next iteration after an error
    `abstract void` | `stop()` This gracefully stops threads of Group
    `abstract boolean` | `stopThread(java.lang.String threadName, boolean now)` Hard or graceful stop depending on now flag
    `abstract void` | `tellThreadsToStop()` This immediately stop threads of Group by interrupting them.
    `void` | `triggerEndOfLoop()` NOOP
    `abstract boolean` | `verifyThreadsStopped()`
    `abstract void` | `waitThreadsStopped()` Wait for all Group Threads to stop after a graceful stop

    - ### Methods inherited from class org.apache.jmeter.testelement.AbstractTestElement

      `addPropertiesValues, addProperty, addProperty, canRemove, clear, clearTemporary, clearTestElementChildren, clone, emptyTemporary, equals, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getSearchableTokens, getThreadContext, getThreadName, hashCode, isEnabled, isRunningVersion, isTemporary, logProperties, mergeIn, propertyIterator, recoverRunningVersion, removeProperty, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse, traverseCollection, traverseMap, traverseProperty`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.jmeter.testelement.TestElement

      `canRemove, clear, clearTestElementChildren, clone, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getThreadContext, getThreadName, isEnabled, isRunningVersion, isTemporary, propertyIterator, recoverRunningVersion, removed, removeProperty, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse`

    - ### Methods inherited from interface org.apache.jmeter.threads.JMeterThreadMonitor

      `threadFinished`

- - ### Field Detail

    - #### ON_SAMPLE_ERROR

          public static final java.lang.String ON_SAMPLE_ERROR

      Action to be taken when a Sampler error occurs
      See Also:
        Constant Field Values

    - #### ON_SAMPLE_ERROR_CONTINUE

          public static final java.lang.String ON_SAMPLE_ERROR_CONTINUE

      Continue, i.e. ignore sampler errors
      See Also:
        Constant Field Values

    - #### ON_SAMPLE_ERROR_START_NEXT_LOOP

          public static final java.lang.String ON_SAMPLE_ERROR_START_NEXT_LOOP

      Start next loop for current thread if sampler error occurs
      See Also:
        Constant Field Values

    - #### ON_SAMPLE_ERROR_STOPTHREAD

          public static final java.lang.String ON_SAMPLE_ERROR_STOPTHREAD

      Stop current thread if sampler error occurs
      See Also:
        Constant Field Values

    - #### ON_SAMPLE_ERROR_STOPTEST

          public static final java.lang.String ON_SAMPLE_ERROR_STOPTEST

      Stop test (all threads) if sampler error occurs, the entire test is stopped at the end of any current samples
      See Also:
        Constant Field Values

    - #### ON_SAMPLE_ERROR_STOPTEST_NOW

          public static final java.lang.String ON_SAMPLE_ERROR_STOPTEST_NOW

      Stop test NOW (all threads) if sampler error occurs, the entire test is stopped abruptly. Any current samplers are interrupted if possible.
      See Also:
        Constant Field Values

    - #### NUM_THREADS

          public static final java.lang.String NUM_THREADS

      Number of threads in the thread group
      See Also:
        Constant Field Values

    - #### MAIN_CONTROLLER

          public static final java.lang.String MAIN_CONTROLLER

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### AbstractThreadGroup

          public AbstractThreadGroup()

  - ### Method Detail

    - #### isDone

          public boolean isDone()

      Indicates whether the Controller is done delivering Samplers for the rest of the test. When the top-level controller returns true to JMeterThread, the thread is complete.
      Specified by:
        `isDone` in interface `Controller`
      Returns:
        boolean

    - #### next

          public Sampler next()

      Delivers the next Sampler or null
      Specified by:
        `next` in interface `Controller`
      Returns:
        org.apache.jmeter.samplers.Sampler or null

    - #### getSamplerController

          public Controller getSamplerController()

      Get the sampler controller.
      Returns:
        the sampler controller.

    - #### setSamplerController

          public void setSamplerController(LoopController c)

      Set the sampler controller.
      Parameters:
        `c` - the sampler controller.

    - #### addTestElement

          public void addTestElement(TestElement child)

      Add a test element.
      Specified by:
        `addTestElement` in interface `TestElement`
      Overrides:
        `addTestElement` in class `AbstractTestElement`
      Parameters:
        `child` - the test element to add.

    - #### addTestElementOnce

          public final boolean addTestElementOnce(TestElement child)

      Add child test element only if it has not already been added.

      Only for use by TestCompiler.

      Specified by:
        `addTestElementOnce` in interface `TestCompilerHelper`
      Parameters:
        `child` - the `TestElement` to be added
      Returns:
        `true` if the child was added

    - #### addIterationListener

          public void addIterationListener(LoopIterationListener lis)

      Controllers have to notify listeners of when they begin an iteration through their sub-elements.
      Specified by:
        `addIterationListener` in interface `Controller`
      Parameters:
        `lis` - The `LoopIterationListener` to add

    - #### removeIterationListener

          public void removeIterationListener(LoopIterationListener iterationListener)

      Unregister IterationListener
      Specified by:
        `removeIterationListener` in interface `Controller`
      Parameters:
        `iterationListener` - `LoopIterationListener`

    - #### initialize

          public void initialize()

      Called to initialize a controller at the beginning of a test iteration.
      Specified by:
        `initialize` in interface `Controller`

    - #### startNextLoop

          public void startNextLoop()

      Start next iteration after an error

    - #### triggerEndOfLoop

          public void triggerEndOfLoop()

      NOOP
      Specified by:
        `triggerEndOfLoop` in interface `Controller`

    - #### setNumThreads

          public void setNumThreads(int numThreads)

      Set the total number of threads to start
      Parameters:
        `numThreads` - the number of threads.

    - #### getNumberOfThreads

          public int getNumberOfThreads()

      Get the number of active threads
      Returns:
        the number of active threads

    - #### getNumThreads

          public int getNumThreads()

      Get the number of threads.
      Returns:
        the number of threads.

    - #### getOnErrorStartNextLoop

          public boolean getOnErrorStartNextLoop()

      Check if a sampler error should cause thread to start next loop.
      Returns:
        true if thread should start next loop

    - #### getOnErrorStopThread

          public boolean getOnErrorStopThread()

      Check if a sampler error should cause thread to stop.
      Returns:
        true if thread should stop

    - #### getOnErrorStopTest

          public boolean getOnErrorStopTest()

      Check if a sampler error should cause test to stop.
      Returns:
        true if test (all threads) should stop

    - #### getOnErrorStopTestNow

          public boolean getOnErrorStopTestNow()

      Check if a sampler error should cause test to stop now.
      Returns:
        true if test (all threads) should stop immediately

    - #### stopThread

          public abstract boolean stopThread(java.lang.String threadName,
                                             boolean now)

      Hard or graceful stop depending on now flag
      Parameters:
        `threadName` - String thread name
        `now` - if true interrupt `Thread`
      Returns:
        boolean true if stop succeeded

    - #### numberOfActiveThreads

          public abstract int numberOfActiveThreads()

      Returns:
        int number of active threads

    - #### start

          public abstract void start(int groupCount,
                                     ListenerNotifier notifier,
                                     ListedHashTree threadGroupTree,
                                     StandardJMeterEngine engine)

      Start the `ThreadGroup`
      Parameters:
        `groupCount` - group number
        `notifier` - `ListenerNotifier`
        `threadGroupTree` - `ListedHashTree`
        `engine` - `StandardJMeterEngine`

    - #### addNewThread

          public abstract JMeterThread addNewThread(int delay,
                                                    StandardJMeterEngine engine)

      Add a new `JMeterThread` to this `ThreadGroup` for engine
      Parameters:
        `delay` - Delay in milliseconds
        `engine` - `StandardJMeterEngine`
      Returns:
        `JMeterThread`

    - #### verifyThreadsStopped

          public abstract boolean verifyThreadsStopped()

      Returns:
        true if threads were correctly stopped

    - #### waitThreadsStopped

          public abstract void waitThreadsStopped()

      Wait for all Group Threads to stop after a graceful stop

    - #### tellThreadsToStop

          public abstract void tellThreadsToStop()

      This immediately stop threads of Group by interrupting them. It differs from `stop()` by being a hard stop

    - #### stop

          public abstract void stop()

      This gracefully stops threads of Group

    - #### breakThreadLoop

          public void breakThreadLoop()

Copyright © 1998-2019 Apache Software Foundation. All Rights Reserved.