<aside> 📚 스레드 스케줄러Thread.yield, 스레드 우선순위에 의존하지 말자. 견고성과 이식성을 모두 해치는 행위이다. 스레드 우선순위는 프로그램의 서비스 품질을 높이는데 드물게 쓰일 수는 있지만 프로그램을 고치는 용도로 사용해서는 절대 안 된다.

</aside>

실행 가능한 스레드 수를 적게 유지하는 방법

public class SlowCountDownLatch {
  private int count;

  public SlowCountDownLatch(int count) {
    if (count < 0) throw new IllegalArgumentException(count + " < 0");
    this.count = count;
  }

  public void await() {
    while (true) {
      synchronized(this) { if (count == 0) return; }
    }
  }

  public synchronized void countDown() {
    if (count != 0) count--;
  }

}

Thread.yield 사용을 주의하라

스레드 우선순위 조정에 주의하라