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