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

Jmeter多线程使用不同授权令牌时步骤执行顺序异常问题

Fixing Multi-Thread Order & Token Conflict in Your JMeter Test

Hey Carlos, I’ve run into this exact issue before with JMeter—let’s break down what’s happening and how to fix it quickly.

The Root Cause

Your problem boils down to two key things:

  • Global Property Overwrites: The ${__setProperty(accessToken,${accessToken})} function stores the token as a global JMeter property. When you fire up multiple threads, they all race to write to this same global variable. Thread 2 might overwrite Thread 1’s token before Thread 1 uses it in the POST request.
  • Parallel Thread Execution: JMeter runs threads in parallel by default. Even though each individual thread executes your 3 steps in order, multiple threads running at the same time can make it look like the overall sequence is "out of order"—and the global token mixup makes the test fail entirely.

The Fixes (From Simplest to Most Specific)

1. Use Thread-Local Variables Instead of Global Properties

Ditch the global property and use a thread-specific variable instead. Replace your __setProperty call with:

${__setVar(accessToken,${accessToken})}

__setVar creates a variable that’s unique to each thread. Now every thread will generate its own access token, store it privately, and use it in its own POST request—no more overwrites.

2. Verify Thread-Level Execution Order

Just to confirm: Each thread in your group will always execute your 3 steps in sequence (Token Request → GET → POST) on its own. The "out of order" appearance is just multiple threads running in parallel. The token fix above will resolve the actual failure, even if the logs look like threads are interleaving.

3. If You Must Use Global Properties (Not Recommended Here)

If for some reason you need a shared token (which doesn’t make sense for a login flow), add a Synchronizing Timer to your thread group. Configure it to wait for all threads to reach the token generation step before proceeding. This forces all threads to generate tokens (or share one) at the same time, but it kills the parallelism you’re trying to test—so only use this if absolutely necessary.

Why Single Thread Worked

With one thread, there’s no competition for the global property. The token gets stored, then used in sequence without any overwrites. Multi-threading introduces that race condition you’re seeing.

Give the __setVar fix a try first—it should resolve both the token conflict and the apparent order issues immediately.

内容的提问来源于stack exchange,提问作者Carlos de la Calle

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 10:23:18