summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/PrioThreadFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/util/PrioThreadFactory.java')
-rw-r--r--src/main/java/org/openslx/util/PrioThreadFactory.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/util/PrioThreadFactory.java b/src/main/java/org/openslx/util/PrioThreadFactory.java
new file mode 100644
index 0000000..d4987cc
--- /dev/null
+++ b/src/main/java/org/openslx/util/PrioThreadFactory.java
@@ -0,0 +1,32 @@
+package org.openslx.util;
+
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class PrioThreadFactory implements ThreadFactory
+{
+
+ private final AtomicInteger counter = new AtomicInteger();
+ private final String name;
+ private final int priority;
+
+ public PrioThreadFactory( String name, int priority )
+ {
+ this.name = name;
+ this.priority = priority;
+ }
+
+ public PrioThreadFactory( String name )
+ {
+ this( name, Thread.NORM_PRIORITY );
+ }
+
+ @Override
+ public Thread newThread( Runnable r )
+ {
+ Thread thread = new Thread( r, name + "-" + counter.incrementAndGet() );
+ thread.setPriority( priority );
+ return thread;
+ }
+
+}