Skip to content

Commit 6fa4c8e

Browse files
committed
ThreadService: give job queue threads better names
Now the thread names use the same convention as ThreadService#run, but instead of thread number suffixes, the suffix is the ID given.
1 parent 02b59b0 commit 6fa4c8e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/java/org/scijava/thread/DefaultThreadService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.concurrent.ExecutorService;
4141
import java.util.concurrent.Executors;
4242
import java.util.concurrent.Future;
43+
import java.util.concurrent.ThreadFactory;
4344

4445
import org.scijava.log.LogService;
4546
import org.scijava.plugin.Parameter;
@@ -188,7 +189,16 @@ private synchronized ExecutorService executor(final String id) {
188189
if (disposed) return null;
189190
if (queues == null) queues = new HashMap<>();
190191
if (!queues.containsKey(id)) {
191-
final ExecutorService queue = Executors.newSingleThreadExecutor();
192+
final ThreadFactory factory = new ThreadFactory() {
193+
194+
@Override
195+
public Thread newThread(final Runnable r) {
196+
final String threadName = contextThreadPrefix() + id;
197+
return new Thread(r, threadName);
198+
}
199+
200+
};
201+
final ExecutorService queue = Executors.newSingleThreadExecutor(factory);
192202
queues.put(id, queue);
193203
}
194204
return queues.get(id);

0 commit comments

Comments
 (0)