Skip to content

Commit

Permalink
No need for CountdownLatch.
Browse files Browse the repository at this point in the history
Use `ExecutorService.awaitTermination` instead.
  • Loading branch information
alcarraz committed Jan 2, 2023
1 parent 8ef249c commit ad341a9
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public class TestRunner
Interpreter bsh;

long timeout;

private CountDownLatch finishLatch;
private static final String NL = System.getProperty("line.separator");
public static final long TIMEOUT = 60000;
public TestRunner () {
Expand All @@ -72,14 +70,13 @@ protected void initService() throws ISOException {
protected void startService() {
int sessions = cfg.getInt("sessions", 1);
ExecutorService executor = Executors.newCachedThreadPool();
finishLatch = new CountDownLatch(sessions);
for (int i=0; i<sessions; i++)
executor.execute(this);

executor.shutdown();
if (cfg.getBoolean ("shutdown")) {
Executors.newSingleThreadExecutor().execute( () -> {
try {
if (!finishLatch.await(timeout, TimeUnit.MILLISECONDS)) {
if (!executor.awaitTermination(timeout, TimeUnit.MILLISECONDS)) {
log.warn("Runners didn't finish before global timeout");
}
} catch (InterruptedException e) {
Expand All @@ -103,7 +100,6 @@ public void run () {
} catch (Throwable t) {
getLog().error (t);
}
finishLatch.countDown();
}
private void runSuite (List suite, MUX mux, Interpreter bsh)
throws ISOException, IOException, EvalError
Expand Down

0 comments on commit ad341a9

Please # to comment.