diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/ThreadUtils.java b/Core/src/org/sleuthkit/autopsy/coreutils/ThreadUtils.java index b9873469e7..8a354a531a 100644 --- a/Core/src/org/sleuthkit/autopsy/coreutils/ThreadUtils.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/ThreadUtils.java @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.coreutils; import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; /* @@ -50,6 +51,35 @@ final public class ThreadUtils { } } + /** + * A thread factory that allows for the creation of distinctly named task + * threads by an ExecutorService constructed using an Executors factory + * method. Each thread created using the factory will be named using the + * thread name and a numerical suffix. + */ + public static class NamedThreadFactory implements ThreadFactory { + + private final String threadName; + + /** + * Contructs a thread factory that allows for the creation of distinctly + * named task threads by an ExecutorService constructed using an + * Executors factory method. Each thread created using the factory will + * be named using the thread name and a numerical suffix. + * + * @param threadName The name of the threads. + */ + public NamedThreadFactory(String threadName) { + this.threadName = threadName; + } + + @Override + public Thread newThread(Runnable task) { + return new Thread(task, threadName); + } + + } + private ThreadUtils() { } }