public class CustomizableThreadFactory extends Object implements ThreadFactory, Serializable
| Modifier and Type | Field and Description |
|---|---|
private boolean |
daemon |
private AtomicInteger |
threadCount |
private ThreadGroup |
threadGroup |
private String |
threadNamePrefix |
private int |
threadPriority |
| Constructor and Description |
|---|
CustomizableThreadFactory(String threadNamePrefix)
Create a new CustomizableThreadCreator with the given thread name prefix.
|
| Modifier and Type | Method and Description |
|---|---|
Thread |
createThread(Runnable runnable)
Template method for the creation of a new
Thread. |
ThreadGroup |
getThreadGroup()
Return the thread group that threads should be created in
(or
null for the default group). |
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.
|
Thread |
newThread(Runnable runnable) |
protected 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(ThreadGroup threadGroup)
Specify the thread group that threads should be created in.
|
void |
setThreadGroupName(String name)
Specify the name of the thread group that threads should be created in.
|
void |
setThreadPriority(int threadPriority)
Set the priority of the threads that this factory creates.
|
private final String threadNamePrefix
private int threadPriority
private boolean daemon
private ThreadGroup threadGroup
private final AtomicInteger threadCount
public CustomizableThreadFactory(String threadNamePrefix)
threadNamePrefix - the prefix to use for the names of newly created threadspublic Thread newThread(Runnable runnable)
newThread in interface ThreadFactorypublic String getThreadNamePrefix()
public void setThreadPriority(int threadPriority)
threadPriority - the thread priorityThread#NORM_PRIORITYpublic 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 at the time that the application itself shuts down.
daemon - the daemonThread#setDaemonpublic boolean isDaemon()
public void setThreadGroupName(String name)
name - the name#setThreadGrouppublic void setThreadGroup(ThreadGroup threadGroup)
threadGroup - the thread group#setThreadGroupNamepublic ThreadGroup getThreadGroup()
null for the default group).public Thread createThread(Runnable runnable)
Thread.
The default implementation creates a new Thread for the given
Runnable, applying an appropriate thread name.
runnable - the Runnable to execute#nextThreadName()protected String nextThreadName()
Thread.
The default implementation returns the specified thread name prefix with an increasing thread count appended: e.g. "SimpleAsyncTaskExecutor-0".
#getThreadNamePrefix()Copyright © 2024. All rights reserved.