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 com.google.common.base.Preconditions;
12 import java.io.Closeable;
13 import java.util.concurrent.ThreadFactory;
14 import java.util.concurrent.atomic.AtomicLong;
15 import javax.annotation.concurrent.ThreadSafe;
18 * Implementation of {@link ThreadFactory}.
21 public class NamingThreadPoolFactory implements ThreadFactory, Closeable {
23 private final ThreadGroup group;
24 private final String namePrefix;
25 private final AtomicLong threadName = new AtomicLong();
27 public NamingThreadPoolFactory(String namePrefix) {
28 Preconditions.checkNotNull(namePrefix);
29 this.group = new ThreadGroup(namePrefix);
30 this.namePrefix = namePrefix;
34 public Thread newThread(Runnable r) {
35 return new Thread(group, r, String.format("%s-%d", group.getName(), threadName.incrementAndGet()));
42 public String getNamePrefix() {