Made executor more resillient
This commit is contained in:
parent
19c2ab446f
commit
43d4e43d99
3 changed files with 84 additions and 18 deletions
|
@ -15,22 +15,20 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
public class Main {
|
||||
private static final String version = "0.3";
|
||||
private static final String version = "0.4";
|
||||
private static final HashMap<String, Integer> data = new HashMap<>();
|
||||
public static Settings conf;
|
||||
static OebbCheck check = new OebbCheck();
|
||||
static long time;
|
||||
static SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
static ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
|
||||
public static ResilientExecutor service = new ResilientExecutor(1);
|
||||
public static final Logger LOG = LoggerFactory.getLogger(Main.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
conf = Settings.getInstance();
|
||||
LOG.info("OebbInfo Version " + version + " starting.");
|
||||
LOG.info("OebbInfo Version {} starting.",version);
|
||||
try {
|
||||
refresh();
|
||||
} catch (IOException e) {
|
||||
|
@ -55,6 +53,16 @@ public class Main {
|
|||
server.setExecutor(null); // creates a default executor
|
||||
server.start();
|
||||
}
|
||||
final Thread mainThread = Thread.currentThread();
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
try {
|
||||
LOG.info("OebbInfo Version {} stopping", version);
|
||||
service.shutdownNow();
|
||||
mainThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
LOG.error("EXCEPTION WHEN STOPPING", e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private static void refresh() throws IOException {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue