[JAVA-13962] Align code with article + clean up (#13012)

* [JAVA-13962] Align code with article + clean up

* [JAVA-13962] Clean up

Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com>
This commit is contained in:
panos-kakos
2022-11-24 19:23:09 +00:00
committed by GitHub
parent 81875ec16b
commit ed92ffdad5
5 changed files with 50 additions and 65 deletions

View File

@@ -0,0 +1,40 @@
package com.baeldung.concurrent.executorservice;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
public class DelayedCallable implements Callable<String> {
private String name;
private long period;
private CountDownLatch latch;
public DelayedCallable(String name, long period, CountDownLatch latch) {
this(name, period);
this.latch = latch;
}
public DelayedCallable(String name, long period) {
this.name = name;
this.period = period;
}
public String call() {
try {
Thread.sleep(period);
if (latch != null) {
latch.countDown();
}
} catch (InterruptedException ex) {
// handle exception
ex.printStackTrace();
Thread.currentThread().interrupt();
}
return name;
}
}