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

io.github.linmoure.thread.factory.NamedThreadFactory Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package io.github.linmoure.thread.factory;

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

public class NamedThreadFactory implements ThreadFactory {
    private static final AtomicInteger TAG = new AtomicInteger(0);
    private final String name;

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

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(r);
        thread.setName(this.name + ":" + TAG.getAndIncrement());
        return thread;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy