前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >JMeter5.1基础类AbstractThreadGroup源码分析

JMeter5.1基础类AbstractThreadGroup源码分析

原创
作者头像
天堂小说
发布2021-12-03 16:42:25
3400
发布2021-12-03 16:42:25
举报
文章被收录于专栏:JMeter源码分析

概述

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();
    }

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
作者已关闭评论
0 条评论
热度
最新
推荐阅读
目录
  • 概述
  • 源码解读
    • 主要变量
      • initialize
        • getSamplerController
          • addTestElementOnce
            • addTestElement
              • next
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档