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.io.IOException;
13 import java.util.concurrent.ThreadFactory;
14 import java.util.concurrent.atomic.AtomicLong;
16 import javax.annotation.concurrent.ThreadSafe;
18 import com.google.common.base.Preconditions;
21 * Implementation of {@link ThreadFactory}.
24 public class NamingThreadPoolFactory implements ThreadFactory, Closeable {
26 private final ThreadGroup group;
27 private final String namePrefix;
28 private final AtomicLong threadName = new AtomicLong();
30 public NamingThreadPoolFactory(String namePrefix) {
31 Preconditions.checkNotNull(namePrefix);
32 this.group = new ThreadGroup(namePrefix);
33 this.namePrefix = namePrefix;
37 public Thread newThread(Runnable r) {
38 return new Thread(group, r, String.format("%s-%d", group.getName(), threadName.incrementAndGet()));
42 public void close() throws IOException {
45 public String getNamePrefix() {