commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [lang] Add a DaemonThreadFactory
Date Tue, 19 Dec 2017 20:34:27 GMT


Am 19.12.2017 um 17:27 schrieb Gary Gregory:
> I keep on copying this from project to project and it seems fitting for
> Commons Lang:

In the concurrent package, there is the BasicThreadFactory class. Could
this class satisfy your needs or can it be extended?

Oliver

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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message