概述
AbstractThreadGroup是JMeter工具线程组的基础类,被ThreadGroup继承。
源码解读
主要变量
代码语言:txt复制 // Only create the map if it is required
private final transient ConcurrentMap<TestElement, Object> children = new ConcurrentHashMap<>();
private static final Object DUMMY = new Object();
/** Action to be taken when a Sampler error occurs */
public static final String ON_SAMPLE_ERROR = "ThreadGroup.on_sample_error"; // int
/** Continue, i.e. ignore sampler errors */
public static final String ON_SAMPLE_ERROR_CONTINUE = "continue";
/** Start next loop for current thread if sampler error occurs */
public static final String ON_SAMPLE_ERROR_START_NEXT_LOOP = "startnextloop";
/** Stop current thread if sampler error occurs */
public static final String ON_SAMPLE_ERROR_STOPTHREAD = "stopthread";
/** Stop test (all threads) if sampler error occurs, the entire test is stopped at the end of any current samples */
public static final String ON_SAMPLE_ERROR_STOPTEST = "stoptest";
/** Stop test NOW (all threads) if sampler error occurs, the entire test is stopped abruptly. Any current samplers are interrupted if possible. */
public static final String ON_SAMPLE_ERROR_STOPTEST_NOW = "stoptestnow";
/** Number of threads in the thread group */
public static final String NUM_THREADS = "ThreadGroup.num_threads";
public static final String MAIN_CONTROLLER = "ThreadGroup.main_controller";
private final AtomicInteger numberOfThreads = new AtomicInteger(0);
initialize
初始化ThreadGroup线程组的LoopController类及其他属性参数
代码语言:txt复制 public void initialize() {
// 获取自带的LoopController类
Controller c = getSamplerController();
JMeterProperty property = c.getProperty(TestElement.NAME);
property.setObjectValue(getName()); // Copy our name into that of the controller
property.setRunningVersion(property.isRunningVersion());// otherwise name reverts
// 初始化threadGroup自带的GenericController类(LoopController的父基类)
c.initialize();
}
getSamplerController
获取ThreadGroup线程组的LoopController类
代码语言:txt复制 public Controller getSamplerController() {
return (Controller) getProperty(MAIN_CONTROLLER).getObjectValue();
}
addTestElementOnce
添加ThreadGroup下的子节点,一次添加一个
代码语言:txt复制 public final boolean addTestElementOnce(TestElement child){
if (children.putIfAbsent(child, DUMMY) == null) {
addTestElement(child);
return true;
}
return false;
}
addTestElement
添加到LoopController类中
代码语言:txt复制 public void addTestElement(TestElement child) {
getSamplerController().addTestElement(child);
}
next
获取controller的sampler采样器和子controller节点
代码语言:txt复制 public Sampler next() {
return getSamplerController().next();
}