logo       

Re: Deamon thread Factory: msg#00043

java.jsr.166-concurrency

Subject: Re: Deamon thread Factory

This is a useful code snippet, especially since Executors.DefaultThreadFactory can't be extended.
I stumbled upon this issue long time ago, and ended up writing a
PriorityThreadFactory - out of
the DefaultThreadFactory implementation.

Seeing this, I now went back and deleted the
PriorityThreadFactory class and done as suggested
below - this is much less error prone.

Thanks.

Moran


Tim Peierls wrote:
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@xxxxxx> 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@xxxxxxxxxxxxxxxxxxxx
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest


_______________________________________________ Concurrency-interest mailing list Concurrency-interest@xxxxxxxxxxxxxxxxxxxx http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@xxxxxxxxxxxxxxxxxxxx
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise