You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <ga...@gmail.com> on 2017/12/19 16:27:26 UTC
[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
Re: [lang] Add a DaemonThreadFactory
Posted by Gary Gregory <ga...@gmail.com>.
Thank you Oliver. I replaced my code with:
import java.util.concurrent.ThreadFactory;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
public final class DaemonThreadFactory {
public static ThreadFactory create(String namingPattern) {
// @formatter:off
return new BasicThreadFactory.Builder()
.namingPattern(namingPattern)
.daemon(true)
.priority(Thread.MAX_PRIORITY)
.build();
// @formatter:on
}
}
Gary
On Tue, Dec 19, 2017 at 1:34 PM, Oliver Heger <ol...@oliver-heger.de>
wrote:
>
>
> 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
>
>
Re: [lang] Add a DaemonThreadFactory
Posted by Oliver Heger <ol...@oliver-heger.de>.
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
Re: [lang] Add a DaemonThreadFactory
Posted by Chas Honton <ch...@honton.org>.
I also have one of these.
+1
Chas
> On Dec 21, 2017, at 7:34 AM, Roger Whitcomb <Ro...@actian.com> wrote:
>
> I have a class almost identical to this in my project, so +1 to this idea.
>
> ~Roger Whitcomb
>
> -----Original Message-----
> From: Gary Gregory [mailto:garydgregory@gmail.com]
> Sent: Tuesday, December 19, 2017 8:27 AM
> To: Commons Developers List <de...@commons.apache.org>
> 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
> B‹KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKCB•È[œÝXœØÜšX™KK[XZ[ˆ]‹][œÝXœØÜšX™PÛÛ[[ۜ˘\XÚK›Ü™ÃB‘›ÜˆY][Û˜[ÛÛ[X[™ËK[XZ[ˆ]‹Z[ÛÛ[[ۜ˘\XÚK›Ü™ÃB
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
RE: [lang] Add a DaemonThreadFactory
Posted by Roger Whitcomb <Ro...@actian.com>.
I have a class almost identical to this in my project, so +1 to this idea.
~Roger Whitcomb
-----Original Message-----
From: Gary Gregory [mailto:garydgregory@gmail.com]
Sent: Tuesday, December 19, 2017 8:27 AM
To: Commons Developers List <de...@commons.apache.org>
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