public class Main { private final static int PRODUCERS = 10; private final static int TO_PRODUCE = 5; private final static int CONSUMERS = 5; private final static int TO_CONSUME = PRODUCERS*TO_PRODUCE/CONSUMERS; private final static int MONITOR_SIZE = 5; public static void main(String[] args) { Monitor monitor = new Monitor(MONITOR_SIZE); Thread[] threads = new Thread[PRODUCERS+CONSUMERS]; // create producers for ( int i = 0; i < PRODUCERS; ++i ) { threads[i] = new Producer(monitor, i, TO_PRODUCE); } // create consumers for ( int i = 0; i < CONSUMERS; ++i ) { threads[PRODUCERS+i] = new Consumer(monitor, i, TO_CONSUME); } // start it all for ( Thread t : threads ) { t.start(); } } }