Implementing Quantitative and Timed Load‑Testing Modes in a Java Performance Framework
This article explains two load‑testing strategies—fixed‑iteration (quantitative) and fixed‑duration (timed)—and provides complete Java implementations, usage guidance, and a Gitee repository link for a multithreaded performance testing framework.
The previous post introduced the multithreaded base class and executor for the performance testing framework; this installment focuses on two load‑testing modes. The quantitative mode runs a fixed number of iterations per thread, while the timed mode runs each thread for a predetermined duration. Both are implemented as virtual classes extending ThreadBase, allowing easy task management and parameter customization.
Quantitative Mode Implementation
The class ThreadLimitTimesCount<T> limits each thread to a specific number of executions. Key fields include times (iteration count), key (global stop flag), and collections for timing marks. The run() method records start time, loops times times, captures execution duration, logs errors, and aggregates results in Concurrent.allTimes and Concurrent.requestMark. Helper methods before(), status(), and after() manage the stop flag, error threshold, and resource cleanup.
Timed Mode Implementation
The class ThreadLimitTimeCount<T> runs until a configured time limit expires. It stores the limit in time (milliseconds) and uses a while(true) loop that breaks when the elapsed time exceeds the limit, an error threshold is reached, or the global stop flag is set. Timing data and marks are collected similarly to the quantitative mode.
Common Features
Both classes share a static logger, a list of marks, and a global key to allow early termination.
The stopAllThread() static method sets key = true to stop all running threads.
Each run() method logs execution count, error count, and total duration, then adds per‑iteration timings to Concurrent.allTimes and request marks to Concurrent.requestMark.
Usage Notes
Quantitative mode offers easier task management and parameter customization but may have larger measurement error; extending the iteration count can mitigate this. Timed mode provides more precise duration control but requires careful handling of the time‑checking loop.
All source code is available at the following repository:
gitee address: https://gitee.com/fanapi/tester
Note: The framework is intended for internal testing purposes; redistribution without permission is prohibited.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
