import java.util.Random; // Class for thread which consumes integers from circular buffer class ConsumeInteger extends Thread { private static final int MAX_SLEEP_TIME = 600; private static final int STOPPING_VALUE = 4; protected HoldInteger circBuffer; // Circular buffer // Store buffer public ConsumeInteger(String name,HoldInteger holder) { super(name); circBuffer = holder; } // Get integers from circular buffer public void run() { Random generator = new Random(); int value = circBuffer.getSharedInt(); // get value from buffer // get values from buffer until get STOPPING_VALUE while (value != STOPPING_VALUE) { try{ sleep((int)(generator.nextInt(MAX_SLEEP_TIME))); } catch (InterruptedException ie) { System.out.println("Exception "+ie.toString()); } value = circBuffer.getSharedInt(); } } }