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.controller.config.threadpool.util;
10 import static java.util.Objects.requireNonNull;
12 import java.io.Closeable;
13 import java.util.concurrent.ThreadFactory;
14 import java.util.concurrent.atomic.AtomicLong;
17 * Implementation of {@link ThreadFactory}. This class is thread-safe.
19 public class NamingThreadPoolFactory implements ThreadFactory, Closeable {
21 private final ThreadGroup group;
22 private final String namePrefix;
23 private final AtomicLong threadName = new AtomicLong();
25 public NamingThreadPoolFactory(final String namePrefix) {
26 this.namePrefix = requireNonNull(namePrefix);
27 this.group = new ThreadGroup(namePrefix);
31 public Thread newThread(final Runnable r) {
32 return new Thread(group, r, String.format("%s-%d", group.getName(), threadName.incrementAndGet()));
39 public String getNamePrefix() {