import java.util.*;

public class ThreadTest {
  
  class MyThread extends Thread {
    public void run() {
      while(true) {
        byte[] b = getArray();
        try {
          Thread.sleep(1000);
        } catch (InterruptedException ie) {
          Thread.currentThread().interrupt();
        }
      }
    }
  }

  ThreadLocal tl = new ThreadLocal();
  List allTL = new ArrayList();
  int count;

  synchronized byte[] getArray() {
    byte[] b = new byte[100*1024];
    tl.set(b);
    count++;
    if (count == 5) {
      //allTL.add(tl);
      tl = new ThreadLocal();
      count = 0;
    }
    return b;
  }

  public static void main(String[] args) {
    ThreadTest test = new ThreadTest();
    test.go();
  }

  public void go() {
    
    for(int i=0;i<9;i++) {
      Thread t = new MyThread();
      t.start();
      try {
        Thread.sleep(100);
      } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
      }
    }

    Thread t = new MyThread();
    t.run();
  }
}