io.bdeploy.common.util.NamedDaemonThreadFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api Show documentation
Show all versions of api Show documentation
Public API including dependencies, ready to be used for integrations and plugins.
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