Skip to content

Java 21: virtual threads for sampler execution + API migration#6685

Open
olka wants to merge 1 commit intoapache:masterfrom
olka:virtual-threads
Open

Java 21: virtual threads for sampler execution + API migration#6685
olka wants to merge 1 commit intoapache:masterfrom
olka:virtual-threads

Conversation

@olka
Copy link
Copy Markdown

@olka olka commented Mar 27, 2026

Summary

  • Virtual threads for sampler execution: ThreadGroup now uses Thread.ofVirtual() for sampler threads and thread starters, reducing OS thread creation by ~3.5x (65 vs 226 thread creates for 200 concurrent users)
  • synchronizedReentrantLock conversions in StandardJMeterEngine, ThreadGroup, JMeterContextService, TestCompiler, AbstractThreadGroup to avoid virtual thread carrier pinning
  • Java 21 API migration: deprecated new URL()URI.create().toURL() in test code, @SuppressWarnings for production code where URI is too strict, new Locale()Locale.of(), Thread.getId()threadId(), removed deprecated ThreadDeath / System.runFinalization() usage
  • Build target: Java 21

Design decision

StandardJMeterEngine.EXECUTOR_SERVICE uses Thread.ofPlatform() (not virtual) — virtual threads are daemon threads and would cause immediate JVM exit in non-GUI mode. Sampler threads remain virtual, tracked via waitThreadsStopped().

A/B Test Results (200 threads, 180s, 30ms server delay)

Metric Virtual Threads Platform Threads (master)
Throughput ~2,450 req/s ~2,390 req/s
Avg latency 79ms 81ms
Max latency 6.5s 7.6s
OS thread creates (JFR) 65 226
Thread alloc stats (JFR) 146 470

Test plan

  • ./gradlew check — all tests pass (only pre-existing batchFTP_TESTS external dependency failure)
  • 180s load test with 200 threads: 440k+ requests, 0 JMeter errors
  • JFR comparison: virtual threads vs platform threads
  • Distributed mode testing (engine executor + remote engines)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant