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
9 package org.opendaylight.controller.config.threadpool.util;
11 import java.io.Closeable;
12 import java.util.concurrent.ExecutorService;
13 import java.util.concurrent.Executors;
14 import java.util.concurrent.ThreadFactory;
15 import java.util.concurrent.ThreadPoolExecutor;
16 import org.opendaylight.controller.config.threadpool.ThreadPool;
19 * Implementation of {@link ThreadPool} using fixed number of threads wraps
20 * {@link ExecutorService}.
22 public class FixedThreadPoolWrapper implements ThreadPool, Closeable {
24 private final ThreadPoolExecutor executor;
26 public FixedThreadPoolWrapper(int threadCount, ThreadFactory factory) {
27 this.executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadCount, factory);
28 executor.prestartAllCoreThreads();
32 public ExecutorService getExecutor() {
33 return Executors.unconfigurableExecutorService(executor);
42 public int getMaxThreadCount() {
43 return executor.getMaximumPoolSize();
46 public void setMaxThreadCount(int maxThreadCount) {
47 executor.setCorePoolSize(maxThreadCount);
48 executor.setMaximumPoolSize(maxThreadCount);