public class ThreadReferencingThreadFactory extends ConfigurableThreadFactory
WeakReference
to each thread. These threads (if still
referenced by the VM) can then be retrieved by using getThreads(boolean)
.Constructor and Description |
---|
ThreadReferencingThreadFactory()
Constructs a new
ThreadReferencingThreadFactory with the default parameters. |
ThreadReferencingThreadFactory(boolean useDaemonThreads)
Constructs a new
ThreadReferencingThreadFactory specifying the behavior for if threads
should be daemon or not. |
ThreadReferencingThreadFactory(ExceptionHandler defaultThreadlyExceptionHandler)
Constructs a new
ConfigurableThreadFactory specifying an ExceptionHandler
that will be provided to all newly created threads. |
ThreadReferencingThreadFactory(int threadPriority)
Constructs a new
ThreadReferencingThreadFactory specifying the priority for produced
threads. |
ThreadReferencingThreadFactory(java.lang.String threadNamePrefix,
boolean appendPoolIdToPrefix)
Constructs a new
ThreadReferencingThreadFactory specifying the prefix for the name of
newly created threads. |
ThreadReferencingThreadFactory(java.lang.String threadNamePrefix,
boolean appendPoolIdToPrefix,
boolean useDaemonThreads,
int threadPriority,
java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler,
ExceptionHandler defaultThreadlyExceptionHandler)
Constructs a new
ThreadReferencingThreadFactory allowing you to provide specific values
for everything which this class allows to be configured. |
ThreadReferencingThreadFactory(java.lang.Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler)
Constructs a new
ThreadReferencingThreadFactory specifying an
Thread.UncaughtExceptionHandler that will be provided to all newly created threads. |
Modifier and Type | Method and Description |
---|---|
java.util.List<java.lang.Thread> |
getThreads(boolean requireAlive)
Get a list of currently known threads.
|
java.lang.Thread |
newThread(java.lang.Runnable r) |
public ThreadReferencingThreadFactory()
ThreadReferencingThreadFactory
with the default parameters. Threads
produced from this should behave exactly like Executors.defaultThreadFactory(), except the
pool number provided in the thread name will be respective to the ones created from other
ThreadReferencingThreadFactory
instances.public ThreadReferencingThreadFactory(java.lang.String threadNamePrefix, boolean appendPoolIdToPrefix)
ThreadReferencingThreadFactory
specifying the prefix for the name of
newly created threads.
If specified with true
for appendPoolIdToPrefix
it will append a unique
"pool" id to the prefix, giving it the format of
threadNamePrefix + UNIQUE_POOL_ID + "-thread-"
. If appendPoolIdToPrefix
is
specified as false
, only a unique thread id will be appended to the prefix. In
either case, the produced threads name will be appended with a unique thread id for the
factory instance.
threadNamePrefix
- prefix for all threads createdappendPoolIdToPrefix
- true
to append a unique pool id to the thread prefixpublic ThreadReferencingThreadFactory(boolean useDaemonThreads)
ThreadReferencingThreadFactory
specifying the behavior for if threads
should be daemon or not.useDaemonThreads
- true
if produced threads should be daemon threadspublic ThreadReferencingThreadFactory(int threadPriority)
ThreadReferencingThreadFactory
specifying the priority for produced
threads.
If the priority is below or above the max available thread priority, this will be adjusted to the limit of the system.
threadPriority
- Priority for newly created threadspublic ThreadReferencingThreadFactory(java.lang.Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler)
ThreadReferencingThreadFactory
specifying an
Thread.UncaughtExceptionHandler
that will be provided to all newly created threads.defaultUncaughtExceptionHandler
- Thread.UncaughtExceptionHandler
to provide to newly created threadspublic ThreadReferencingThreadFactory(ExceptionHandler defaultThreadlyExceptionHandler)
ConfigurableThreadFactory
specifying an ExceptionHandler
that will be provided to all newly created threads.defaultThreadlyExceptionHandler
- ExceptionHandler
to provide to newly created threadspublic ThreadReferencingThreadFactory(java.lang.String threadNamePrefix, boolean appendPoolIdToPrefix, boolean useDaemonThreads, int threadPriority, java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler, ExceptionHandler defaultThreadlyExceptionHandler)
ThreadReferencingThreadFactory
allowing you to provide specific values
for everything which this class allows to be configured. You must use this constructor if
you need to adjust two or more values.
If specified with true
for appendPoolIdToPrefix
it will append a unique
"pool" id to the prefix, giving it the format of
threadNamePrefix + UNIQUE_POOL_ID + "-thread-"
. If appendPoolIdToPrefix
is
specified as false
, only a unique thread id will be appended to the prefix. In
either case, the produced threads name will be appended with a unique thread id for the
factory instance.
If the priority is below or above the max available thread priority, this will be adjusted to the limit of the system.
threadNamePrefix
- prefix for all threads created, null
to match defaultappendPoolIdToPrefix
- true
to append a unique pool id to the thread prefix,
true
to match defaultuseDaemonThreads
- true if produced threads should be daemon threads, false to match defaultthreadPriority
- Priority for newly created threads, Thread.NORM_PRIORITY
to match defaultuncaughtExceptionHandler
- UncaughtExceptionHandler to provide to newly created threads,
null
to match defaultdefaultThreadlyExceptionHandler
- ExceptionHandler
to provide to newly created threadspublic java.util.List<java.lang.Thread> getThreads(boolean requireAlive)
requireAlive
- true
to only provide threads currently seen as alivepublic java.lang.Thread newThread(java.lang.Runnable r)
newThread
in interface java.util.concurrent.ThreadFactory
newThread
in class ConfigurableThreadFactory