//-*-java-*- Main { public static void main(String args[]) (@ BStack stack = new BStack(); new Thread(new Stacker(stack, BStack.PUT)).start(); try { // Thread.sleep(2000); Thread.sleep(20); } catch(InterruptedException e) {} new Thread(new Stacker(stack, BStack.TAKE)).start(); @) } Stacker { (@ private BStack _stack; private int _func; Stacker(BStack stack, int func) { _stack=stack; _func=func; } @) public void run() (@ switch(_func) { case BStack.PUT: beginPutting(); break; case BStack.TAKE: beginTaking(); break; } @) private void beginPutting() (@{ Random rand = new Random(); for(int i=0;i<6;i++) { double rv = rand.nextDouble(); System.out.println("Attempting put("+rv+") @ " +System.currentTimeMillis()); _stack.put(rv); System.out.println("Put: "+rv+" @ " +System.currentTimeMillis()); try { Thread.sleep(800); } catch(InterruptedException e) {} } }@) private void beginTaking() (@ { for(int i=0;i<6;i++) { System.out.println("Attempting take() @ " +System.currentTimeMillis()); double took = _stack.take(); System.out.println("Took: "+took+" @ " +System.currentTimeMillis()); try { // Thread.sleep(400); Thread.sleep(20); } catch(InterruptedException e) {} } }@) } BStack { (@ public final int SIZE = 6; private double[] stuff = new double[SIZE]; // private int[] stuff = new int[2]; private int count1 = 0; public static final int PUT = 1; public static final int TAKE = 2; @) public double put(double thing) (@{ stuff[count1++] = thing; return thing; }@) public double take() (@{ return stuff[--count1]; }@) }