2 * Copyright (c) 2013 Cisco Systems, Inc. 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.openflowplugin.impl.util;
10 import com.google.common.util.concurrent.ThreadFactoryBuilder;
11 import java.util.concurrent.BlockingQueue;
12 import java.util.concurrent.ThreadPoolExecutor;
13 import java.util.concurrent.TimeUnit;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * threadPoolExecutor implementation logging exceptions thrown by threads.
20 public class ThreadPoolLoggingExecutor extends ThreadPoolExecutor {
22 private static final Logger LOG = LoggerFactory.getLogger(ThreadPoolLoggingExecutor.class);
27 * @param corePoolSize thread pool size
28 * @param maximumPoolSize maximum pool size
29 * @param keepAliveTime keep alive time
30 * @param unit time unit
31 * @param workQueue task queue
32 * @param poolName thread name prefix
34 public ThreadPoolLoggingExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit,
35 BlockingQueue<Runnable> workQueue, final String poolName) {
36 super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
37 new ThreadFactoryBuilder().setNameFormat(poolName + "-%d").build());
41 protected void afterExecute(Runnable runnable, Throwable throwable) {
42 super.afterExecute(runnable, throwable);
43 // in case of executing pure Runnable
44 if (throwable != null) {
45 LOG.warn("thread in pool stopped with error", throwable);