Package org.apache.jmeter.threads
Class AbstractThreadGroup
java.lang.Object
org.apache.jmeter.testelement.AbstractTestElement
org.apache.jmeter.threads.AbstractThreadGroup
- All Implemented Interfaces:
Serializable
,Cloneable
,Controller
,Searchable
,org.apache.jmeter.testelement.TestElement
,JMeterThreadMonitor
,TestCompilerHelper
- Direct Known Subclasses:
ThreadGroup
public abstract class AbstractThreadGroup
extends AbstractTestElement
implements Serializable, Controller, JMeterThreadMonitor, TestCompilerHelper
ThreadGroup holds the settings for a JMeter thread group.
This class is intended to be ThreadSafe.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.jmeter.testelement.TestElement
org.apache.jmeter.testelement.TestElement.Companion
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Duration
static final String
The same user or different usersstatic final String
static final String
Number of threads in the thread groupstatic final String
Action to be taken when a Sampler error occursstatic final String
Continue, i.e.static final String
Start next loop for current thread if sampler error occursstatic final String
Stop test (all threads) if sampler error occurs, the entire test is stopped at the end of any current samplesstatic final String
Stop test NOW (all threads) if sampler error occurs, the entire test is stopped abruptly.static final String
Stop current thread if sampler error occursFields inherited from interface org.apache.jmeter.testelement.TestElement
COMMENTS, Companion, ENABLED, GUI_CLASS, NAME, TEST_CLASS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Controllers have to notify listeners of when they begin an iteration through their sub-elements.abstract JMeterThread
addNewThread
(int delay, StandardJMeterEngine engine) Add a newJMeterThread
to thisThreadGroup
for enginevoid
addTestElement
(org.apache.jmeter.testelement.TestElement child) Add a test element.final boolean
addTestElementOnce
(org.apache.jmeter.testelement.TestElement child) Add child test element only if it has not already been added.void
static ListedHashTree
cloneTree
(ListedHashTree tree) int
Get the number of active threadsint
Get the number of threads.boolean
Check if a sampler error should cause thread to start next loop.boolean
Check if a sampler error should cause test to stop.boolean
Check if a sampler error should cause test to stop now.boolean
Check if a sampler error should cause thread to stop.@NotNull org.apache.jmeter.testelement.schema.PropertiesAccessor<? extends AbstractThreadGroup,
? extends org.apache.jmeter.threads.AbstractThreadGroupSchema> getProps()
Get the sampler controller.org.apache.jmeter.threads.AbstractThreadGroupSchema
void
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.boolean
Get kind of user: true means same user running multiple iterations false means a different user for each iterationprotected JMeterThread
makeThread
(StandardJMeterEngine engine, JMeterThreadMonitor monitor, ListenerNotifier notifier, int groupNumber, int threadNumber, ListedHashTree threadGroupTree, JMeterVariables variables) CreateJMeterThread
.next()
Delivers the next Sampler or nullabstract int
void
removeIterationListener
(LoopIterationListener iterationListener) Unregister IterationListenervoid
setIsSameUserOnNextIteration
(boolean isSameUserOnNextIteration) Set the kind of uservoid
setNumThreads
(int numThreads) Set the total number of threads to startvoid
Set the sampler controller.abstract void
start
(int groupCount, ListenerNotifier notifier, ListedHashTree threadGroupTree, StandardJMeterEngine engine) Start theThreadGroup
void
Start next iteration after an errorabstract void
stop()
This gracefully stops threads of Groupabstract boolean
stopThread
(String threadName, boolean now) Hard or graceful stop depending on now flagabstract void
This immediately stop threads of Group by interrupting them.void
NOOPabstract boolean
abstract void
Wait for all Group Threads to stop after a graceful stopMethods 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, getPropertyOrNull, 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.threads.JMeterThreadMonitor
threadFinished
Methods inherited from interface org.apache.jmeter.testelement.TestElement
canRemove, clear, clearTestElementChildren, clone, get, get, get, get, get, get, get, get, get, getComment, getName, getOrCreate, getOrCreate, getOrNull, getOrNull, getOrNull, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getPropertyOrNull, getPropertyOrNull, getString, getThreadContext, getThreadName, isEnabled, isRunningVersion, isTemporary, propertyIterator, recoverRunningVersion, removed, removeProperty, removeProperty, set, set, set, set, set, set, set, set, set, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse
-
Field Details
-
DEFAULT_THREAD_STOP_TIMEOUT
-
ON_SAMPLE_ERROR
Action to be taken when a Sampler error occurs- See Also:
-
ON_SAMPLE_ERROR_CONTINUE
Continue, i.e. ignore sampler errors- See Also:
-
ON_SAMPLE_ERROR_START_NEXT_LOOP
Start next loop for current thread if sampler error occurs- See Also:
-
ON_SAMPLE_ERROR_STOPTHREAD
Stop current thread if sampler error occurs- See Also:
-
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:
-
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:
-
NUM_THREADS
Number of threads in the thread group- See Also:
-
MAIN_CONTROLLER
- See Also:
-
IS_SAME_USER_ON_NEXT_ITERATION
The same user or different users- See Also:
-
-
Constructor Details
-
AbstractThreadGroup
public AbstractThreadGroup()
-
-
Method Details
-
getSchema
public org.apache.jmeter.threads.AbstractThreadGroupSchema getSchema()- Specified by:
getSchema
in interfaceorg.apache.jmeter.testelement.TestElement
-
getProps
@NotNull public @NotNull org.apache.jmeter.testelement.schema.PropertiesAccessor<? extends AbstractThreadGroup,? extends org.apache.jmeter.threads.AbstractThreadGroupSchema> getProps()- Specified by:
getProps
in interfaceorg.apache.jmeter.testelement.TestElement
-
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 interfaceController
- Returns:
- boolean
-
next
Delivers the next Sampler or null- Specified by:
next
in interfaceController
- Returns:
- org.apache.jmeter.samplers.Sampler or null
-
getSamplerController
Get the sampler controller.- Returns:
- the sampler controller.
-
setSamplerController
Set the sampler controller.- Parameters:
c
- the sampler controller.
-
addTestElement
public void addTestElement(org.apache.jmeter.testelement.TestElement child) Add a test element.- Specified by:
addTestElement
in interfaceorg.apache.jmeter.testelement.TestElement
- Overrides:
addTestElement
in classAbstractTestElement
- Parameters:
child
- the test element to add.
-
addTestElementOnce
public final boolean addTestElementOnce(org.apache.jmeter.testelement.TestElement child) Add child test element only if it has not already been added.Only for use by TestCompiler.
- Specified by:
addTestElementOnce
in interfaceTestCompilerHelper
- Parameters:
child
- theTestElement
to be added- Returns:
true
if the child was added
-
addIterationListener
Controllers have to notify listeners of when they begin an iteration through their sub-elements.- Specified by:
addIterationListener
in interfaceController
- Parameters:
lis
- TheLoopIterationListener
to add
-
removeIterationListener
Unregister IterationListener- Specified by:
removeIterationListener
in interfaceController
- Parameters:
iterationListener
-LoopIterationListener
-
initialize
public void initialize()Called to initialize a controller at the beginning of a test iteration.- Specified by:
initialize
in interfaceController
-
startNextLoop
public void startNextLoop()Start next iteration after an error -
triggerEndOfLoop
public void triggerEndOfLoop()NOOP- Specified by:
triggerEndOfLoop
in interfaceController
-
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
Hard or graceful stop depending on now flag- Parameters:
threadName
- String thread namenow
- if true interruptThread
- 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 theThreadGroup
- Parameters:
groupCount
- group numbernotifier
-ListenerNotifier
threadGroupTree
-ListedHashTree
engine
-StandardJMeterEngine
-
addNewThread
Add a newJMeterThread
to thisThreadGroup
for engine- Parameters:
delay
- Delay in millisecondsengine
-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 fromstop()
by being a hard stop -
stop
public abstract void stop()This gracefully stops threads of Group -
breakThreadLoop
public void breakThreadLoop() -
setIsSameUserOnNextIteration
public void setIsSameUserOnNextIteration(boolean isSameUserOnNextIteration) Set the kind of user- Parameters:
isSameUserOnNextIteration
- true is the same user on next iteration of loop false is a different user on next iteration of loop
-
isSameUserOnNextIteration
public boolean isSameUserOnNextIteration()Get kind of user:- true means same user running multiple iterations
- false means a different user for each iteration
- Returns:
- the kind of user.
-
makeThread
@API(status=EXPERIMENTAL, since="5.5") protected JMeterThread makeThread(StandardJMeterEngine engine, JMeterThreadMonitor monitor, ListenerNotifier notifier, int groupNumber, int threadNumber, ListedHashTree threadGroupTree, JMeterVariables variables) CreateJMeterThread
. Note: the input tree is not cloned.- Parameters:
engine
-StandardJMeterEngine
monitor
-JMeterThreadMonitor
notifier
-ListenerNotifier
groupNumber
- thread group numberthreadNumber
- int thread numberthreadGroupTree
-ListedHashTree
variables
- initial variables- Returns:
JMeterThread
-
cloneTree
- Parameters:
tree
-ListedHashTree
- Returns:
- a clone of tree
-