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

javax.jmdns.impl.util.NamedThreadFactory Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 3.6.0
Show newest version
// 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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy