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

io.bdeploy.common.util.NamedDaemonThreadFactory Maven / Gradle / Ivy

Go to download

Public API including dependencies, ready to be used for integrations and plugins.

There is a newer version: 7.3.6
Show newest version
package io.bdeploy.common.util;

import java.util.concurrent.ThreadFactory;
import java.util.function.Supplier;

/**
 * A {@link ThreadFactory} which provides better names to threads.
 */
public class NamedDaemonThreadFactory implements ThreadFactory {

    private final Supplier nameSupplier;

    public NamedDaemonThreadFactory(String name) {
        this(() -> name);
    }

    public NamedDaemonThreadFactory(Supplier nameSupplier) {
        this.nameSupplier = nameSupplier;
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread t = new Thread(r);
        t.setDaemon(true);
        t.setName(nameSupplier.get());
        return t;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy