Class Adept2ThreadFactory
java.lang.Object
de.aristaflow.adept2.util.threading.Adept2ThreadFactory
- All Implemented Interfaces:
Thread.UncaughtExceptionHandler,ThreadFactory
public class Adept2ThreadFactory
extends Object
implements ThreadFactory, Thread.UncaughtExceptionHandler
The default thread factory overwritten to name the threads.
Executors.defaultThreadFactory()-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final RunnableThe cleanup runnable injected into all created threads to be executed just before the thread terminates.protected final booleanWhether to create daemon threads.protected final ThreadGroupThe group for the threads.protected final LoggerLogger for logging uncaught exceptions.protected final StringThe prefix of the thread name, naming the user of this thread factory.protected static final AtomicIntegerThe counter for the pools.protected final intThe priority for the created threads.protected final longThe desired stack size (in Bytes) for any new thread in bytes of address space.protected final AtomicIntegerThe counter for the threads. -
Constructor Summary
ConstructorsConstructorDescriptionAdept2ThreadFactory(String name, boolean daemon, Logger logger) Creates a new thread factory with the designated name, a default stack size, a priority one less than normal.Adept2ThreadFactory(String name, int priority, Logger logger) Creates a new thread factory with the designated parameters and a default stack size for non-daemon threads.Adept2ThreadFactory(String name, long stackSize, int priority, boolean daemon, Runnable cleanup, Logger logger) Creates a new thread factory with the designated parameters.Adept2ThreadFactory(String name, long stackSize, int priority, boolean daemon, Logger logger) Creates a new thread factory with the designated parameters.Adept2ThreadFactory(String name, long stackSize, int priority, Logger logger) Creates a new thread factory with the designated parameters for non-daemon threads.Adept2ThreadFactory(String name, long stackSize, Logger logger) Creates a new thread factory with the designated parameters and a priority one less than normal and non-daemon threads.Adept2ThreadFactory(String name, Runnable cleanup, Logger logger) Creates a new thread factory with the designated name, a default stack size and a priority one less than normal.Adept2ThreadFactory(String name, Logger logger) Creates a new thread factory with the designated name, a default stack size and a priority one less than normal. -
Method Summary
Modifier and TypeMethodDescriptionGets the logger this factory uses for uncaught exceptions.Gets the name prefix this factory uses for new threads.voiduncaughtException(Thread t, Throwable e)
-
Field Details
-
poolNumber
The counter for the pools. -
group
The group for the threads. -
threadNumber
The counter for the threads. -
namePrefix
The prefix of the thread name, naming the user of this thread factory. -
stackSize
protected final long stackSizeThe desired stack size (in Bytes) for any new thread in bytes of address space. -
priority
protected final int priorityThe priority for the created threads. -
daemon
protected final boolean daemonWhether to create daemon threads. -
cleanup
The cleanup runnable injected into all created threads to be executed just before the thread terminates. -
logger
Logger for logging uncaught exceptions.
-
-
Constructor Details
-
Adept2ThreadFactory
Creates a new thread factory with the designated name, a default stack size and a priority one less than normal.- Parameters:
name- The name of the pool, used to identify the threadlogger- The logger of the caller, to which uncaught exceptions are going to be logged.
-
Adept2ThreadFactory
Creates a new thread factory with the designated name, a default stack size and a priority one less than normal.- Parameters:
name- The name of the pool, used to identify the threadcleanup- A cleanup runnable injected into all created threads to be executed just before the thread terminates.logger- The logger of the caller, to which uncaught exceptions are going to be logged.
-
Adept2ThreadFactory
Creates a new thread factory with the designated name, a default stack size, a priority one less than normal.- Parameters:
name- The name of the pool, used to identify the threadlogger- The logger of the caller, to which uncaught exceptions are going to be logged.daemon- Whether to create daemon threads.
-
Adept2ThreadFactory
Creates a new thread factory with the designated parameters and a priority one less than normal and non-daemon threads.- Parameters:
name- The name of the pool, used to identify the threadstackSize- The desired stack size (in KiB) for the new thread, or zero to indicate that this parameter is to be ignored.logger- The logger of the caller, to which uncaught exceptions are going to be logged.
-
Adept2ThreadFactory
Creates a new thread factory with the designated parameters and a default stack size for non-daemon threads.- Parameters:
name- The name of the pool, used to identify the threadpriority- The priority of the created threads.logger- The logger of the caller, to which uncaught exceptions are going to be logged.
-
Adept2ThreadFactory
Creates a new thread factory with the designated parameters for non-daemon threads.- Parameters:
name- The name of the pool, used to identify the threadstackSize- The desired stack size (in KiB) for the new thread, or zero to indicate that this parameter is to be ignored.priority- The priority of the created threads. If this is lower thanThread.MIN_PRIORITY,Thread.MIN_PRIORITYwill be used, the same applies inversely toThread.MAX_PRIORITY.logger- The logger of the caller, to which uncaught exceptions are going to be logged.
-
Adept2ThreadFactory
public Adept2ThreadFactory(String name, long stackSize, int priority, boolean daemon, Logger logger) Creates a new thread factory with the designated parameters.- Parameters:
name- The name of the pool, used to identify the threadstackSize- The desired stack size (in KiB) for the new thread, or zero to indicate that this parameter is to be ignored.priority- The priority of the created threads. If this is lower thanThread.MIN_PRIORITY,Thread.MIN_PRIORITYwill be used, the same applies inversely toThread.MAX_PRIORITY.daemon- Whether to create daemon threads.logger- The logger of the caller, to which uncaught exceptions are going to be logged.
-
Adept2ThreadFactory
public Adept2ThreadFactory(String name, long stackSize, int priority, boolean daemon, Runnable cleanup, Logger logger) Creates a new thread factory with the designated parameters.- Parameters:
name- The name of the pool, used to identify the threadstackSize- The desired stack size (in KiB) for the new thread, or zero to indicate that this parameter is to be ignored.priority- The priority of the created threads. If this is lower thanThread.MIN_PRIORITY,Thread.MIN_PRIORITYwill be used, the same applies inversely toThread.MAX_PRIORITY.daemon- Whether to create daemon threads.cleanup- A cleanup runnable injected into all created threads to be executed just before the thread terminates.logger- The logger of the caller, to which uncaught exceptions are going to be logged.
-
-
Method Details
-
newThread
- Specified by:
newThreadin interfaceThreadFactory
-
uncaughtException
- Specified by:
uncaughtExceptionin interfaceThread.UncaughtExceptionHandler
-
getNamePrefix
Gets the name prefix this factory uses for new threads.- Returns:
- The name prefix this factory uses for new threads.
-
getLogger
Gets the logger this factory uses for uncaught exceptions.- Returns:
- The logger this factory uses for uncaught exceptions.
-