javax.jmdns.impl.util.NamedThreadFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmdns Show documentation
Show all versions of jmdns Show documentation
JmDNS is a Java implementation of multi-cast DNS and can be used for service registration and discovery in local area networks. JmDNS is fully compatible with Apple's Bonjour.
The project was originally started in December 2002 by Arthur van Hoff at Strangeberry.
// Copyright 2003-2012 Arthur van Hoff, Rick Blair
// Licensed under Apache License version 2.0
// Original license LGPL
package javax.jmdns.impl.util;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
/**
* Custom thread factory which sets the name to make it easier to identify where the pooled threads were created.
*
* @author Trejkaz, Pierre Frisch
*/
public class NamedThreadFactory implements ThreadFactory {
private final ThreadFactory _delegate;
private final String _namePrefix;
/**
* Constructs the thread factory.
*
* @param namePrefix a prefix to append to thread names (will be separated from the default thread name by a space.)
*/
public NamedThreadFactory(String namePrefix) {
this._namePrefix = namePrefix;
_delegate = Executors.defaultThreadFactory();
}
@Override
public Thread newThread(Runnable runnable) {
Thread thread = _delegate.newThread(runnable);
thread.setName(_namePrefix + ' ' + thread.getName());
return thread;
}
}