I have a class almost identical to this in my project, so +1 to this idea.

~Roger Whitcomb

-----Original Message-----
From: Gary Gregory [mailto:[email protected]] 
Sent: Tuesday, December 19, 2017 8:27 AM
To: Commons Developers List <[email protected]>
Subject: [lang] Add a DaemonThreadFactory

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

Reply via email to