I\'m looking for the simplest, most straightforward way to implement the following:
As others here have mentioned, your best bet is to make a thread pool with the Executors class:
However, if you want to roll your own, this code should give you an idea how to proceed. Basically, just add every new thread to a thread group and make sure that you never have more than N active threads in the group:
Task[] tasks = getTasks(); // array of tasks to complete
ThreadGroup group = new ThreadGroup();
int i=0;
while( i0 ) {
if( group.activeCount()