////// PipeWordCount.java ////// import java.io.*; class PipeWordCount { public static void main(String args[]) throws IOException { PipedReader reader = new PipedReader(); PipedWriter writer = new PipedWriter(reader); PipeProducer pd = new PipeProducer(writer); PipeConsumer cs = new PipeConsumer(reader); pd.start(); // producer thread now running cs.start(); // consumer thread now running try { pd.join(); cs.join(); } catch(InterruptedException e) { } System.out.println("total " + cs.count() + " words"); } }