2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.elan.l2gw.ha.listeners;
10 import com.google.common.util.concurrent.ThreadFactoryBuilder;
11 import java.util.concurrent.ExecutorService;
12 import java.util.concurrent.Executors;
13 import java.util.concurrent.ThreadFactory;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 public final class HAJobScheduler implements Thread.UncaughtExceptionHandler {
20 private static final Logger LOG = LoggerFactory.getLogger(HAJobScheduler.class);
21 ExecutorService executorService;
23 static HAJobScheduler instance = new HAJobScheduler();
25 private HAJobScheduler() {
26 ThreadFactory threadFact = new ThreadFactoryBuilder()
27 .setNameFormat("hwvtep-ha-task-%d").setUncaughtExceptionHandler(this).build();
28 executorService = Executors.newSingleThreadScheduledExecutor(threadFact);
29 //TODO put metric for waiting job
32 public static HAJobScheduler getInstance() {
36 public void setThreadPool(ExecutorService service) {
37 executorService = service;
40 public void submitJob(Runnable runnable) {
41 executorService.execute(runnable);
45 public void uncaughtException(Thread thread, Throwable throwable) {
46 LOG.error("Failed to execute task", throwable);