blob: 1c73ff1d08ae58d4a3c77fd589725ac48dd87fab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package org.openecomp.sdc.be.components.scheduledtasks;
import org.openecomp.sdc.common.log.wrappers.Logger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
public abstract class AbstractScheduleTaskRunner {
private static final Logger log = Logger.getLogger(AbstractScheduleTaskRunner.class);
public abstract ExecutorService getExecutorService();
protected void shutdownExecutor() {
ExecutorService executorService = getExecutorService();
if (executorService == null)
return;
executorService.shutdown(); // Disable new tasks from being submitted
try {
// Wait a while for existing tasks to terminate
if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
executorService.shutdownNow(); // Cancel currently executing
// tasks
// Wait a while for tasks to respond to being cancelled
if (!executorService.awaitTermination(60, TimeUnit.SECONDS))
log.debug("Pool did not terminate");
}
} catch (InterruptedException ie) {
// (Re-)Cancel if current thread also interrupted
executorService.shutdownNow();
// Preserve interrupt status
Thread.currentThread().interrupt();
}
}
}
|