
7.28 Errors and Exceptions in Java and Multithreaded Programming
Buffer Position :7 Filled. Buffer Position :8 Filled.
Displaying items from Buffer.
Item1,Item2,Item3,Item4,Item5,Item6,Item7,Item8,
Line Nos. 43 & 44: create objects for Producer and Consumer.
Line Nos. 46 & 47: create new thread objects thrdProd and thrdCons.
Line Nos. 48 & 49: start the threads.
Line No. 4: creates StringBuffer object called buffer and constructor at Line
No. 6 allocates resources.
Producer produces in a for loop continuously and fills up the buffer through append state-
ment at Line No. 14. Note that buffer is in a synchronized block defined at Line No. 9.