[concurrency-interest] Deamon thread Factory

Tim Peierls tim at peierls.net
Fri Oct 20 10:45:12 EDT 2006


Daemon threads should be used sparingly, for reasons given in Sec 7.4.2 of
JCiP. Adding such a method to Executors would inevitably encourage people to
use daemon threads even where inappropriate. Better to have the folks who
really need a daemonThreadFactory() method roll their own. It's easy enough:

public static ThreadFactory daemonThreadFactory() {
    final ThreadFactory f = Executors.defaultThreadFactory();
    return new ThreadFactory() {
        public Thread newThread(Runnable r) {
            Thread t = f.newThread(r);
            t.setDaemon(true);
            return t;
        }
    };
}

--tim

On 10/20/06, Kasper Nielsen <kav at it.edu> wrote:
>
> Hi,
>
> I find myself using daemon threads quite often. However the utility
> class Executors lacks methods for this. It would be nice with an easy
> way to create daemon threads.
>
> Perhaps a static ThreadFactory daemonThreadFactory(); method
>
> - Kasper
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20061020/e513137f/attachment.html 


More information about the Concurrency-interest mailing list