// // Class for "thread manager" analogous to "threadManager" C++ // class (see file pthreads-threadManager.h). // public class ThreadManager { private Thread[] threads; // Constructor -- create threads. public ThreadManager(Runnable[] objs) { threads = new Thread[objs.length]; for (int i = 0; i < threads.length; ++i) threads[i] = new Thread(objs[i]); } // Start all threads. public void start() { for (int i = 0; i < threads.length; ++i) threads[i].start(); } // Wait for all threads to complete. public void join() { // ("join" is declared as possibly throwing an exception, // so to keep the compiler happy we must deal with it.) try { for (int i = 0; i < threads.length; ++i) threads[i].join(); } catch (InterruptedException e) { // should never happen } } }