[Solved] Optimizing thread calls in Java [closed]

[ad_1]

Use a loop and an ExecutorService.

ExecutorService executor = Executors.newCachedThreadPool();
for (int i = 0; i < count; i++) {
    executor.execute(new TokenStarter());
}

That should recreate your code, but is not optimal. You probably want to limit the amount of threads that run concurrently:

ExecutorService executor = Executors.newFixedThreadPool(desiredParallelism);

[ad_2]

solved Optimizing thread calls in Java [closed]