Switch to CountDownLatch

This commit is contained in:
huangyuhui 2016-03-05 13:23:16 +08:00
parent 5d4a3c1df6
commit 7c2cfc171e
2 changed files with 12 additions and 16 deletions

View File

@ -24,7 +24,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@ -72,12 +72,12 @@ public class TaskList extends Thread {
private class Invoker implements Runnable {
Task task;
Set<Invoker> s;
CountDownLatch latch;
AtomicBoolean bool;
public Invoker(Task task, Set<Invoker> ss, AtomicBoolean bool) {
public Invoker(Task task, CountDownLatch latch, AtomicBoolean bool) {
this.task = task;
s = ss;
this.latch = latch;
this.bool = bool;
}
@ -85,7 +85,7 @@ public class TaskList extends Thread {
public void run() {
if (!executeTask(task))
bool.set(false);
s.remove(this);
latch.countDown();
}
}
@ -99,22 +99,18 @@ public class TaskList extends Thread {
return true;
this.totTask += c.size();
AtomicBoolean bool = new AtomicBoolean(true);
Set<Invoker> runningThread = Collections.synchronizedSet(new HashSet<Invoker>());
CountDownLatch counter = new CountDownLatch(c.size());
for (Task t2 : c) {
t2.setParallelExecuting(true);
Invoker thread = new Invoker(t2, runningThread, bool);
runningThread.add(thread);
Invoker thread = new Invoker(t2, counter, bool);
invokers.add(thread);
if (!EXECUTOR_SERVICE.isShutdown() && !EXECUTOR_SERVICE.isTerminated())
futures.put(thread, EXECUTOR_SERVICE.submit(thread));
}
while (!runningThread.isEmpty())
try {
if (this.isInterrupted())
return false;
Thread.sleep(1);
} catch (InterruptedException ignore) {
}
try {
counter.await();
} catch (InterruptedException ignore) {
}
return bool.get();
}

View File

@ -30,7 +30,7 @@ if (buildnumber == null)
def versionroot = System.getenv("VERSION_ROOT")
if (versionroot == null)
versionroot = "0.8.6"
versionroot = "0.8.7"
String mavenGroupId = 'HMCSM'
String mavenVersion = versionroot + '.' + buildnumber