All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.archaius.util.ThreadFactories Maven / Gradle / Ivy

There is a newer version: 2.8.2
Show newest version
package com.netflix.archaius.util;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class ThreadFactories {
    
    private static final AtomicInteger counter = new AtomicInteger();
    
    public static ThreadFactory newNamedDaemonThreadFactory(final String name) {
       
        return new ThreadFactory() {
            @Override
            public Thread newThread(Runnable runnable) {
                Thread thread = Executors.defaultThreadFactory().newThread(runnable);
                thread.setDaemon(true);
                thread.setName(String.format(name, counter.incrementAndGet()));
                return thread;
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy