JMeter special thread groups let a test plan prepare state before the measured workload and clean it up after the regular users finish. A setUp Thread Group can seed records, create sessions, or reset fixture data, while a tearDown Thread Group can remove temporary records or release test-only resources.
Both special groups use the normal Thread Group controls, including user count, ramp-up, loop count, and sampler scope. Keep their sampler labels explicit because their samples can still appear in result files, and avoid putting measured business traffic in either special group when the main load profile belongs in a regular Thread Group.
JMeter does not treat teardown as guaranteed cleanup for every stop path. A gracefully stopped test needs the Run tearDown Thread Groups after shutdown of main threads option on the Test Plan, and a forced stop can still skip the tearDown Thread Group.
Name: setUp Thread Group - seed checkout fixture Number of Threads (users): 1 Loop Count: 1
Use enough threads and loops for the setup work only. Do not mirror the main load profile unless the setup action itself needs concurrency.
Sampler label: setUp - seed checkout fixture Purpose: create or reset data needed by the main workload
Name: Thread Group - run checkout sampler Sampler label: main - run checkout sampler
The regular Thread Group is the workload whose timing, errors, and throughput normally matter for the load test.
Name: tearDown Thread Group - remove checkout fixture Number of Threads (users): 1 Loop Count: 1
Sampler label: tearDown - remove checkout fixture Purpose: remove temporary data created for the validation run
Do not put required production cleanup only in tearDown when operators may use forced stops. Use an external cleanup path for state that must always be removed.
Test Plan option: Run tearDown Thread Groups after shutdown of main threads
This option applies to graceful shutdown of the main threads. A forced stop can still bypass teardown.
setUp marker: 01 setUp: seed checkout fixture main marker: 02 main: run checkout sampler tearDown marker: 03 tearDown: remove checkout fixture
A temporary JSR223 Sampler can write these lines to a file such as setup-teardown-order.txt during a small validation run. Remove marker-only samplers after the order is proven.
setup-teardown-thread-groups-configure.jmx
$ jmeter -n -t setup-teardown-thread-groups-configure.jmx -l setup-teardown-results.jtl -j jmeter.log Creating summariser <summary> Created the tree successfully using setup-teardown-thread-groups-configure.jmx Starting standalone test @ 2026 Jun 30 08:21:00 GMT Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445 summary + 1 in 00:00:00 = 2.3/s Avg: 425 Min: 425 Max: 425 Err: 0 (0.00%) Active: 1 Started: 1 Finished: 0 summary + 2 in 00:00:00 = 40.8/s Avg: 12 Min: 11 Max: 14 Err: 0 (0.00%) Active: 0 Started: 1 Finished: 1 summary = 3 in 00:00:00 = 6.2/s Avg: 150 Min: 11 Max: 425 Err: 0 (0.00%) Tidying up ... ... end of run
A three-sample validation run matches one setup sample, one main sample, and one teardown sample. Use a larger smoke run only when the setup or cleanup action needs more than one iteration.
Related: How to run a JMeter test from the command line
$ cat setup-teardown-order.txt 01 setUp: seed checkout fixture 02 main: run checkout sampler 03 tearDown: remove checkout fixture
$ cat setup-teardown-results.jtl timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect 1782807660819,425,setUp - seed checkout fixture,200,OK,setUp Thread Group - seed checkout fixture 1-1,text,true,,23,0,1,1,null,0,0,0 1782807661263,14,main - run checkout sampler,200,OK,Thread Group - run checkout sampler 1-1,text,true,,20,0,1,1,null,0,0,0 1782807661279,11,tearDown - remove checkout fixture,200,OK,tearDown Thread Group - remove checkout fixture 1-1,text,true,,24,0,1,1,null,0,0,0