1 19 20 package org.netbeans.modules.j2ee.metadata; 21 22 35 public final class CountLatch { 36 37 private int count = 0; 38 39 public CountLatch() { 40 } 41 42 51 public void await() throws InterruptedException { 52 synchronized (this) { 53 while (count > 0) { 54 wait(); 55 } 56 } 57 } 58 59 62 public void countUp() { 63 synchronized (this) { 64 count++; 65 } 66 } 67 68 77 public void countDown() { 78 synchronized (this) { 79 if (count != 0) { 80 count--; 81 if (count == 0) { 82 notifyAll(); 83 } 84 } 85 } 86 } 87 88 93 public int getCount() { 94 synchronized (this) { 95 return count; 96 } 97 } 98 99 } 100 | Popular Tags |