public class CircularBufferTest
1: // Fig 23.14: CircularBufferTest.java
2: // Application shows two threads manipulating a circular buffer.
3: import java.util.concurrent.ExecutorService;
4: import java.util.concurrent.Executors;
5:
6: public class CircularBufferTest
7: {
8: public static void main( String[] args )
9: {
10: // create new thread pool with two threads
11: ExecutorService application = Executors.newFixedThreadPool( 2 );
12:
13: // create CircularBuffer to store ints
14: Buffer sharedLocation = new CircularBuffer();
15:
16: try // try to start producer and consumer
17: {
18: application.execute( new Producer( sharedLocation ) );
19: application.execute( new Consumer( sharedLocation ) );
20: } // end try
21: catch ( Exception exception )
22: {
23: exception.printStackTrace();
24: } // end catch
25:
26: application.shutdown();
27: } // end main
28: } // end class CircularBufferTest
29:
30:
31:
32: /**************************************************************************
33: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
34: * Pearson Education, Inc. All Rights Reserved. *
35: * *
36: * DISCLAIMER: The authors and publisher of this book have used their *
37: * best efforts in preparing the book. These efforts include the *
38: * development, research, and testing of the theories and programs *
39: * to determine their effectiveness. The authors and publisher make *
40: * no warranty of any kind, expressed or implied, with regard to these *
41: * programs or to the documentation contained in these books. The authors *
42: * and publisher shall not be liable in any event for incidental or *
43: * consequential damages in connection with, or arising out of, the *
44: * furnishing, performance, or use of these programs. *
45: *************************************************************************/