I'm using the native ProcessBuilder class to create a variably sized list of process objects. Currently, I simply roll through the list calling the start method on each Process instance. I would however like to better control this aspect of the application by limiting the number of my running processes to a custom value (e.g. number of processors). What data structure(s), existing library, or model best suit this task?
Example
List<Process> processList = new ArrayList<Process>();
ProcessBuilder pb1 = new ProcessBuilder("myCommand", "myArg1", "myArg2");
ProcessBuilder pb2 = new ProcessBuilder("myCommand", "myArg1", "myArg2");
processList.add(pb1);
processList.add(pb2)
for(Process p : processList)
(
// more control is needed here
p.start();
}