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
_______________________________________________
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
|