I have the following requirement.
I am trying to build a simulator that will generate load on a system for the purpose of load testing. I want threads to start every X milliseconds, each of which will kick off a task that takes Y milliseconds, with Y being maybe 2 or 3 orders of magnitude > X.
I had thought I could use ScheduledExecutorService.scheduleAtFixedRate(). It hasn't worked. I see the following javadoc comment which explains why:
If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.
Concurrent execution is precisely what I want. I want to start a lot of tasks in separate threads, let them do whatever they do, with a big thread pool, and finish when they finish. The point is to generate load for testing load.
Is there anything available in java.util.concurrent that would let me do so? I am reading these javadocs but they are making my head spin now.
You can use the
scheduleAtFixedRate(control, 10l, 1l, TimeUnit.SEDONDS)
scheduler to create and execute new tasks (in other threads), similar to: