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

org.asteriskjava.util.DaemonThreadFactory Maven / Gradle / Ivy

There is a newer version: 3.41.0
Show newest version
package org.asteriskjava.util;

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

/**
 * A ThreadFactory that creates daemon threads for use with an {@link Executor}.
 *
 * @author srt
 * @version $Id$
 * @since 0.3
 */
public class DaemonThreadFactory implements ThreadFactory {
    private static final AtomicInteger poolNumber = new AtomicInteger(1);
    private final AtomicInteger threadNumber = new AtomicInteger(1);
    private final String namePrefix;

    /**
     * Creates a new instance.
     */
    public DaemonThreadFactory() {
        namePrefix = "AJ DaemonPool-" + poolNumber.getAndIncrement() + '.';
    }//new


    @Override
    public Thread newThread(Runnable r) {
        final Thread thread = new Thread(r);
        thread.setDaemon(true);
        thread.setName(namePrefix + threadNumber.getAndIncrement());

        return thread;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy