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

os.failsafe.executor.utils.NamedThreadFactory Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package os.failsafe.executor.utils;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicLong;

public class NamedThreadFactory implements ThreadFactory {

    private final AtomicLong threadIndex = new AtomicLong(0);
    private final String threadNamePrefix;

    public NamedThreadFactory(String threadNamePrefix) {
        this.threadNamePrefix = threadNamePrefix;
    }

    @Override
    public Thread newThread(Runnable runnable) {
        Thread thread = new Thread(runnable);
        thread.setName(threadNamePrefix + threadIndex.getAndIncrement());
        return thread;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy