import java.util.concurrent.*;

public class Consumer implements Runnable {
   public Consumer(BlockingQueue<Character> bb) {
      b=bb;
   }
   public void run() {
      try {
         synchronized (System.out) {
            System.out.println("Thread: "+Thread.currentThread().getName()+" gestart");
         }
         for (int i=0; i<2000; ++i) {
            char c=b.take();
            synchronized (System.out) {
               System.out.print(c);
            }
         }
         synchronized (System.out) {
            System.out.println("Thread: "+Thread.currentThread().getName()+" gestopt");
         }
      }
      catch(InterruptedException e) {
         System.err.println("Thread: "+Thread.currentThread().getName()+" interrupted");
      }
   }
   private BlockingQueue<Character> b;
}
