Remove unused exceptions
[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
9 package org.opendaylight.controller.config.threadpool.util;
10
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;
16
17 /**
18  * Implementation of {@link ThreadFactory}.
19  */
20 @ThreadSafe
21 public class NamingThreadPoolFactory implements ThreadFactory, Closeable {
22
23     private final ThreadGroup group;
24     private final String namePrefix;
25     private final AtomicLong threadName = new AtomicLong();
26
27     public NamingThreadPoolFactory(String namePrefix) {
28         Preconditions.checkNotNull(namePrefix);
29         this.group = new ThreadGroup(namePrefix);
30         this.namePrefix = namePrefix;
31     }
32
33     @Override
34     public Thread newThread(Runnable r) {
35         return new Thread(group, r, String.format("%s-%d", group.getName(), threadName.incrementAndGet()));
36     }
37
38     @Override
39     public void close() {
40     }
41
42     public String getNamePrefix() {
43         return namePrefix;
44     }
45
46 }