commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject [lang] Add a DaemonThreadFactory
Date Tue, 19 Dec 2017 16:27:26 GMT
I keep on copying this from project to project and it seems fitting for
Commons Lang:

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicLong;

public final class DaemonThreadFactory implements ThreadFactory {

    private final static AtomicLong COUNT = new AtomicLong(1);

    private final String name;

    public DaemonThreadFactory(final String name) {
        super();
        this.name = name;
    }

    @Override
    public Thread newThread(final Runnable r) {
        final Thread thread = new Thread(r, name + " " +
COUNT.getAndIncrement());
        thread.setDaemon(true);
        return thread;
    }

}

Thoughts?

Gary

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message