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

com.kqinfo.universal.delay.task.thread.NameThreadFactory Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
package com.kqinfo.universal.delay.task.thread;

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

/**
 * @author Zijian Liao
 * @since 1.14.0
 */
public class NameThreadFactory implements ThreadFactory {
    
    private final AtomicInteger id = new AtomicInteger(0);
    
    private final String name;
    
    public NameThreadFactory(String name) {
        if(!name.endsWith("-")){
            name = name + "-";
        }
        this.name = name;
    }
    
    @Override
    public Thread newThread(Runnable r) {
        String threadName = name + id.getAndIncrement();
        Thread thread = new Thread(r, threadName);
        thread.setDaemon(true);
        return thread;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy