Bump odlparent to 5.0.0
[controller.git] / opendaylight / config / threadpool-config-impl / src / main / java / org / opendaylight / controller / config / threadpool / util / NamingThreadPoolFactory.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.config.threadpool.util;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.io.Closeable;
13 import java.util.concurrent.ThreadFactory;
14 import java.util.concurrent.atomic.AtomicLong;
15
16 /**
17  * Implementation of {@link ThreadFactory}. This class is thread-safe.
18  */
19 public class NamingThreadPoolFactory implements ThreadFactory, Closeable {
20
21     private final ThreadGroup group;
22     private final String namePrefix;
23     private final AtomicLong threadName = new AtomicLong();
24
25     public NamingThreadPoolFactory(final String namePrefix) {
26         this.namePrefix = requireNonNull(namePrefix);
27         this.group = new ThreadGroup(namePrefix);
28     }
29
30     @Override
31     public Thread newThread(final Runnable r) {
32         return new Thread(group, r, String.format("%s-%d", group.getName(), threadName.incrementAndGet()));
33     }
34
35     @Override
36     public void close() {
37     }
38
39     public String getNamePrefix() {
40         return namePrefix;
41     }
42 }