Source of UnsynchronizedBuffer.java


  1: // Fig. 23.9: UnsynchronizedBuffer.java
  2: // UnsynchronizedBuffer represents a single shared integer.
  3: 
  4: public class UnsynchronizedBuffer implements Buffer 
  5: {
  6:    private int buffer = -1; // shared by producer and consumer threads
  7: 
  8:    // place value into buffer
  9:    public void set( int value )
 10:    {
 11:       System.out.printf( "Producer writes\t%2d", value );
 12:       buffer = value;
 13:    } // end method set
 14: 
 15:    // return value from buffer
 16:    public int get()
 17:    {
 18:       System.out.printf( "Consumer reads\t%2d", buffer );
 19:       return buffer; 
 20:    } // end method get
 21: } // end class UnsynchronizedBuffer
 22: 
 23: 
 24: 
 25: /**************************************************************************
 26:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 27:  * Pearson Education, Inc. All Rights Reserved.                           *
 28:  *                                                                        *
 29:  * DISCLAIMER: The authors and publisher of this book have used their     *
 30:  * best efforts in preparing the book. These efforts include the          *
 31:  * development, research, and testing of the theories and programs        *
 32:  * to determine their effectiveness. The authors and publisher make       *
 33:  * no warranty of any kind, expressed or implied, with regard to these    *
 34:  * programs or to the documentation contained in these books. The authors *
 35:  * and publisher shall not be liable in any event for incidental or       *
 36:  * consequential damages in connection with, or arising out of, the       *
 37:  * furnishing, performance, or use of these programs.                     *
 38:  *************************************************************************/