public class CustomizableThreadCreator
extends java.lang.Object
implements java.io.Serializable
Serves as base class for thread factories such as
CustomizableThreadFactory
.
CustomizableThreadFactory
,
Serialized FormModifier and Type | Class and Description |
---|---|
private static class |
CustomizableThreadCreator.SerializableMonitor
Empty class used for a serializable monitor object.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
daemon |
private int |
threadCount |
private java.lang.Object |
threadCountMonitor |
private java.lang.ThreadGroup |
threadGroup |
private java.lang.String |
threadNamePrefix |
private int |
threadPriority |
Constructor and Description |
---|
CustomizableThreadCreator()
Create a new CustomizableThreadCreator with default thread name prefix.
|
CustomizableThreadCreator(java.lang.String threadNamePrefix)
Create a new CustomizableThreadCreator with the given thread name prefix.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Thread |
createThread(java.lang.Runnable runnable)
Template method for the creation of a Thread.
|
protected java.lang.String |
getDefaultThreadNamePrefix()
Build the default thread name prefix for this factory.
|
java.lang.ThreadGroup |
getThreadGroup()
Return the thread group that threads should be created in
(or
null ) for the default group. |
java.lang.String |
getThreadNamePrefix()
Return the thread name prefix to use for the names of newly
created threads.
|
int |
getThreadPriority()
Return the priority of the threads that this factory creates.
|
boolean |
isDaemon()
Return whether this factory should create daemon threads.
|
protected java.lang.String |
nextThreadName()
Return the thread name to use for a newly created thread.
|
void |
setDaemon(boolean daemon)
Set whether this factory is supposed to create daemon threads,
just executing as long as the application itself is running.
|
void |
setThreadGroup(java.lang.ThreadGroup threadGroup)
Specify the thread group that threads should be created in.
|
void |
setThreadGroupName(java.lang.String name)
Specify the name of the thread group that threads should be created in.
|
void |
setThreadNamePrefix(java.lang.String threadNamePrefix)
Specify the prefix to use for the names of newly created threads.
|
void |
setThreadPriority(int threadPriority)
Set the priority of the threads that this factory creates.
|
private java.lang.String threadNamePrefix
private int threadPriority
private boolean daemon
private java.lang.ThreadGroup threadGroup
private int threadCount
private final java.lang.Object threadCountMonitor
public CustomizableThreadCreator()
public CustomizableThreadCreator(java.lang.String threadNamePrefix)
threadNamePrefix
- the prefix to use for the names of newly created threadspublic void setThreadNamePrefix(java.lang.String threadNamePrefix)
public java.lang.String getThreadNamePrefix()
public void setThreadPriority(int threadPriority)
Thread.NORM_PRIORITY
public int getThreadPriority()
public void setDaemon(boolean daemon)
Default is "false": Concrete factories usually support explicit cancelling. Hence, if the application shuts down, Runnables will by default finish their execution.
Specify "true" for eager shutdown of threads which still actively execute a Runnable.
Thread.setDaemon(boolean)
public boolean isDaemon()
public void setThreadGroupName(java.lang.String name)
public void setThreadGroup(java.lang.ThreadGroup threadGroup)
setThreadGroupName(java.lang.String)
public java.lang.ThreadGroup getThreadGroup()
null
) for the default group.public java.lang.Thread createThread(java.lang.Runnable runnable)
Default implementation creates a new Thread for the given Runnable, applying an appropriate thread name.
runnable
- the Runnable to executenextThreadName()
protected java.lang.String nextThreadName()
Default implementation returns the specified thread name prefix with an increasing thread count appended: for example, "SimpleAsyncTaskExecutor-0".
getThreadNamePrefix()
protected java.lang.String getDefaultThreadNamePrefix()
null
)