I want to schedule the same command in a parallel fashion using executor service in Java. I wrote a wrapper over thread pool executor, which takes the parallel count to schedule the command as parameter and in a for loop, schedules the command(i.e. same instance multiple times).
Is this approach correct? Is there any suggested way of doing this? I am using spring to create these beans.
You could use the
ScheduledExecuterServiceas follows:This will execute the
runmethod every second starting immediately.With this approach you can add it multiple times to the
scheduledExecuterService: