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
Fields Modifier and Type Field Description protected Runnable
cleanup
The cleanup runnable injected into all created threads to be executed just before the thread terminates.protected boolean
daemon
Whether to create daemon threads.protected ThreadGroup
group
The group for the threads.protected Logger
logger
Logger for logging uncaught exceptions.protected String
namePrefix
The prefix of the thread name, naming the user of this thread factory.protected static AtomicInteger
poolNumber
The counter for the pools.protected int
priority
The priority for the created threads.protected long
stackSize
The desired stack size (in Bytes) for any new thread in bytes of address space.protected AtomicInteger
threadNumber
The counter for the threads.
-
Constructor Summary
Constructors Constructor Description Adept2ThreadFactory(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Logger
getLogger()
Gets the logger this factory uses for uncaught exceptions.String
getNamePrefix()
Gets the name prefix this factory uses for new threads.Thread
newThread(Runnable r)
void
uncaughtException(Thread t, Throwable e)
-
-
-
Field Detail
-
poolNumber
protected static final AtomicInteger poolNumber
The counter for the pools.
-
group
protected final ThreadGroup group
The group for the threads.
-
threadNumber
protected final AtomicInteger threadNumber
The counter for the threads.
-
namePrefix
protected final String namePrefix
The prefix of the thread name, naming the user of this thread factory.
-
stackSize
protected final long stackSize
The desired stack size (in Bytes) for any new thread in bytes of address space.
-
priority
protected final int priority
The priority for the created threads.
-
daemon
protected final boolean daemon
Whether to create daemon threads.
-
cleanup
protected final Runnable cleanup
The cleanup runnable injected into all created threads to be executed just before the thread terminates.
-
logger
protected final Logger logger
Logger for logging uncaught exceptions.
-
-
Constructor Detail
-
Adept2ThreadFactory
public 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.- 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
public 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.- 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
public Adept2ThreadFactory(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.- 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
public 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.- 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
public 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.- 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
public Adept2ThreadFactory(String name, long stackSize, int priority, Logger logger)
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_PRIORITY
will 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_PRIORITY
will 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_PRIORITY
will 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 Detail
-
newThread
public Thread newThread(Runnable r)
- Specified by:
newThread
in interfaceThreadFactory
-
uncaughtException
public void uncaughtException(Thread t, Throwable e)
- Specified by:
uncaughtException
in interfaceThread.UncaughtExceptionHandler
-
getNamePrefix
public String getNamePrefix()
Gets the name prefix this factory uses for new threads.- Returns:
- The name prefix this factory uses for new threads.
-
getLogger
public Logger getLogger()
Gets the logger this factory uses for uncaught exceptions.- Returns:
- The logger this factory uses for uncaught exceptions.
-
-