AbstractThreadGroup是JMeter工具线程组的基础类,被ThreadGroup继承。
// 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);
初始化ThreadGroup线程组的LoopController类及其他属性参数
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();
}
获取ThreadGroup线程组的LoopController类
public Controller getSamplerController() {
return (Controller) getProperty(MAIN_CONTROLLER).getObjectValue();
}
添加ThreadGroup下的子节点,一次添加一个
public final boolean addTestElementOnce(TestElement child){
if (children.putIfAbsent(child, DUMMY) == null) {
addTestElement(child);
return true;
}
return false;
}
添加到LoopController类中
public void addTestElement(TestElement child) {
getSamplerController().addTestElement(child);
}
获取controller的sampler采样器和子controller节点
public Sampler next() {
return getSamplerController().next();
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。