From 9e893bcf9bbf43bbb0e3f441285f8eac8e76482c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 14 May 2018 15:58:57 +0200 Subject: Add PrioThreadFactory --- .../java/org/openslx/util/PrioThreadFactory.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/org/openslx/util/PrioThreadFactory.java (limited to 'src/main/java/org/openslx/util/PrioThreadFactory.java') 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; + } + +} -- cgit v1.2.3-55-g7522