You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JMeter正则表达式提取器输出数量可变时的多值处理求助

Solution for Dynamic Value Passing Across Thread Groups & Stable Looping in JMeter (Non-GUI Friendly)

Got it, let's tackle your problem step by step. We need two core pieces here: safely passing dynamic extracted values between thread groups, and implementing a loop that avoids the stack overflow issue with For Loop Controller in non-GUI mode.

1. Cross-Thread Group Value Transfer: Using JMeter Properties

Since thread groups in JMeter are isolated by default, we'll use global JMeter properties to share the extracted values. These properties are accessible across all thread groups once set.

Step 1: Store Extracted Values in Properties (First Thread Group)

Add a JSR223 PostProcessor right after your Regular Expression Extractor (with reference name request) and use this Groovy script to save all captured values and their total count:

// Get total number of matches from the regex extractor
def totalMatches = vars.get("request_matchNr") as int

// Save total count to a global property
props.put("request_total", totalMatches.toString())

// Loop through each captured value and store in global properties
for (int i = 1; i <= totalMatches; i++) {
    def capturedValue = vars.get("request_" + i)
    if (capturedValue != null) {
        props.put("request_" + i, capturedValue)
    }
}
  • vars: Accesses current thread's local variables (from the regex extractor)
  • props: Accesses global JMeter properties (cross-thread group accessible)

2. Stable Loop Implementation (Second Thread Group)

Instead of For Loop Controller (which causes stack overflow in non-GUI for large iterations), we'll use a While Controller combined with script-based counter management. This approach is lighter and avoids stack accumulation.

Step 2.1: Initialize Counter & Total Count

Add a JSR223 Sampler at the start of your second thread group to set up the loop variables:

// Initialize loop counter to 1
vars.put("current_index", "1")

// Pull total match count from global properties
def totalRequests = props.get("request_total") as int
vars.put("request_total", totalRequests.toString())

Step 2.2: Set Up While Controller

Add a While Controller with this condition (uses JEXL3 for safe numerical comparison):

${__jexl3(${current_index} <= ${request_total},)}

This will keep the loop running until the counter exceeds the total number of captured requests.

Step 2.3: Configure HTTP Request Inside the Loop

In your HTTP request, reference the current captured value using the __P() function (to read global properties):

${__P(request_${current_index},)}

This dynamically pulls request_1, request_2, etc., as the loop progresses.

Step 2.4: Increment Counter

Add a JSR223 PostProcessor right after the HTTP request to increment the counter:

def current = vars.get("current_index") as int
current++
vars.put("current_index", current.toString())

Critical Configuration Note

Make sure to enable Run thread groups consecutively in your Test Plan settings. This ensures the first thread group finishes extracting and storing all values before the second thread group starts its loop.

Why This Works

  • Cross-thread safety: JMeter properties are global, so values set by the first thread group are available to the second once it starts.
  • Non-GUI stability: The While Controller + scripted counter avoids the stack overflow issue of For Loop Controller, as each iteration is processed independently without accumulating stack frames.

内容的提问来源于stack exchange,提问作者iSavvy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:41:22