From b8a251d05658a1f263b994b081348e38a71afdf8 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 26 Feb 2016 01:46:09 +0100 Subject: [PATCH] Cleaned up unnecessary NamedThreadFactory id's. Added @Property annotation --- Dorkbox-Util/src/dorkbox/util/NamedThreadFactory.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Dorkbox-Util/src/dorkbox/util/NamedThreadFactory.java b/Dorkbox-Util/src/dorkbox/util/NamedThreadFactory.java index 1e3b9e2..041963c 100644 --- a/Dorkbox-Util/src/dorkbox/util/NamedThreadFactory.java +++ b/Dorkbox-Util/src/dorkbox/util/NamedThreadFactory.java @@ -23,7 +23,7 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class NamedThreadFactory implements ThreadFactory { - private static final AtomicInteger poolId = new AtomicInteger(); + private final AtomicInteger poolId = new AtomicInteger(); // permit this to be changed! /** @@ -35,10 +35,9 @@ class NamedThreadFactory implements ThreadFactory { *

* Stack size must be specified in bytes. Default is 8k */ + @Property public static int stackSizeForThreads = 8192; - private final AtomicInteger nextId = new AtomicInteger(); - private final ThreadGroup group; private final String namePrefix; private final int threadPriority; @@ -100,7 +99,7 @@ class NamedThreadFactory implements ThreadFactory { public NamedThreadFactory(String poolNamePrefix, ThreadGroup group, int threadPriority, boolean isDaemon) { this.daemon = isDaemon; - this.namePrefix = poolNamePrefix + '-' + poolId.incrementAndGet(); + this.namePrefix = poolNamePrefix; if (group == null) { this.group = Thread.currentThread() .getThreadGroup(); @@ -122,7 +121,7 @@ class NamedThreadFactory implements ThreadFactory { // 8k is the size of the android stack. Depending on the version of android, this can either change, or will always be 8k // To be honest, 8k is pretty reasonable for an asynchronous/event based system (32bit) or 16k (64bit) // Setting the size MAY or MAY NOT have any effect!!! - Thread t = new Thread(this.group, r, this.namePrefix + '-' + this.nextId.incrementAndGet(), stackSizeForThreads); + Thread t = new Thread(this.group, r, this.namePrefix + '-' + this.poolId.incrementAndGet(), stackSizeForThreads); t.setDaemon(this.daemon); if (t.getPriority() != this.threadPriority) { t.setPriority(this.threadPriority);