class Monitor{
 private char buffer[];
 private int n = 0;
 private boolean isMt = true, isFul = false;
 
 public Monitor(int N){
  buffer = new char[N];
 }
 public synchronized char get(){
  while(isMt == true)
   try{
    wait();
   } catch (InterruptedException e){}
  char x = buffer[n-1]; n--;
  if(n <= 0) isMt = true;
  else isFul = false;
  notify();
  return (x);
 }
 public synchronized void put(char c){
  while(isFul == true)
   try{
    wait();
   } catch (InterruptedException e) {}
  buffer[n++] = c;
  if (n >= buffer.length) isFul = true;
  else isMt = false;
  notify();
 }
 
 public static void main(String args[]){
  Monitor montor = new Monitor(10);
  Producer p = new Producer(montor, 1000);
  Consumer c = new Consumer(montor, 1000);
  p.start();
  c.start();
 }
}

class Producer extends Thread {
 private Monitor monitor; int N, count = 0;
 private String key = \" abcdefghijklmnopqrstuvwxyz.,?!\"; 
 public Producer(Monitor monitor, int n){ this.monitor = monitor; N = n;}
 public void run() {
  for (int i = 0; i < N; i++){
   char c = key.charAt((int) (Math.random() * 31));
   monitor.put(c);
   try{
    sleep(1000 * (int)Math.random());
   } catch (Exception e) {}
  }
 }
}

class Consumer extends Thread{ // Consumer
 private Monitor monitor; int N;
 public Consumer(Monitor monitor, int n){ this.monitor = monitor; N = n; }
 public void run(){
  for (int i = 0; i < N; i++){
   char c = monitor.get();
   System.out.print(c);
   if(i % 100 == 99) System.out.println(); // 요건 그냥 보기편하라고 100자 쓸때마다 줄 바꿈
   try{
    sleep(1000 * (int)Math.random());
   } catch(Exception e){}
  }
 }
}

소스가 좀 긴가....
대략 설명하면 쓰레드 연습한다고 만드는건데;;; 32가지 key 값안에 문자 랜덤하게 1000게 뽑아서 버퍼에서 보내고 그걸 출력하는거거든??
근대 이게 1000개의 문자가 랜덤하게 나오게 했는데
각 문자별로 카운트 해서 몇번씩 나왔는지 그래프를 만드려고하는데
각 문자 몇번나왔는지 카운트 할 방법 아시는분 좀 갈쳐줘... 배열 써보고 여러가지 끄적거려봤는데...
잘 안되네;; ㅠ_