Fixes threading issue in DependencyChecker

This commit is contained in:
konsoletyper 2014-01-10 15:30:41 +04:00
parent 2214433d6c
commit ca29e10aeb
2 changed files with 9 additions and 7 deletions

View File

@ -106,7 +106,9 @@ public class DependencyChecker {
} }
void schedule(final Runnable runnable) { void schedule(final Runnable runnable) {
synchronized (activeTaskMonitor) {
activeTaskCount.incrementAndGet(); activeTaskCount.incrementAndGet();
}
try { try {
executor.execute(new Runnable() { executor.execute(new Runnable() {
@Override public void run() { @Override public void run() {
@ -117,8 +119,8 @@ public class DependencyChecker {
exceptionOccured.compareAndSet(null, e); exceptionOccured.compareAndSet(null, e);
executor.shutdownNow(); executor.shutdownNow();
} }
if (activeTaskCount.decrementAndGet() == 0) {
synchronized (activeTaskMonitor) { synchronized (activeTaskMonitor) {
if (activeTaskCount.decrementAndGet() == 0) {
activeTaskMonitor.notifyAll(); activeTaskMonitor.notifyAll();
} }
} }
@ -131,11 +133,11 @@ public class DependencyChecker {
public void checkDependencies() { public void checkDependencies() {
while (true) { while (true) {
try {
synchronized (activeTaskMonitor) {
if (activeTaskCount.get() == 0 || exceptionOccured.get() != null) { if (activeTaskCount.get() == 0 || exceptionOccured.get() != null) {
break; break;
} }
try {
synchronized (activeTaskMonitor) {
activeTaskMonitor.wait(); activeTaskMonitor.wait();
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {