Top Description Fields Constructors Methods
org.springframework.util

public Class CustomizableThreadCreator

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.springframework.core.task.SimpleAsyncTaskExecutor
Annotations
@SuppressWarnings:serial
Imports
java.io.Serializable, java.util.concurrent.atomic.AtomicInteger, org.springframework.lang.Nullable

Simple customizable helper class for creating new Thread instances. Provides various bean properties: thread name prefix, thread priority, etc.

Serves as base class for thread factories such as org.springframework.scheduling.concurrent.CustomizableThreadFactory.

Author
Juergen Hoeller
Since
2.0.3
See Also
org.springframework.scheduling.concurrent.CustomizableThreadFactory

Field Summary

Modifier and TypeField and Description
private boolean
private final AtomicInteger
private ThreadGroup
private String
private int

Constructor Summary

AccessConstructor and Description
public
CustomizableThreadCreator()

Create a new CustomizableThreadCreator with default thread name prefix.

public
CustomizableThreadCreator(String
the prefix to use for the names of newly created threads
threadNamePrefix
)

Create a new CustomizableThreadCreator with the given thread name prefix.

Method Summary

Modifier and TypeMethod and Description
public Thread
createThread(Runnable
the Runnable to execute
runnable
)

Template method for the creation of a new Thread.

protected String

Returns:

the default thread name prefix (never null)
getDefaultThreadNamePrefix
()

Build the default thread name prefix for this factory.

public ThreadGroup
getThreadGroup()

Return the thread group that threads should be created in (or null for the default group).

public String
getThreadNamePrefix()

Return the thread name prefix to use for the names of newly created threads.

public int
getThreadPriority()

Return the priority of the threads that this factory creates.

public boolean
isDaemon()

Return whether this factory should create daemon threads.

protected String
nextThreadName()

Return the thread name to use for a newly created Thread.

public void
setDaemon(boolean daemon)

Set whether this factory is supposed to create daemon threads, just executing as long as the application itself is running.

public void
setThreadGroup(ThreadGroup threadGroup)

Specify the thread group that threads should be created in.

public void
setThreadGroupName(String name)

Specify the name of the thread group that threads should be created in.

public void
setThreadNamePrefix(String threadNamePrefix)

Specify the prefix to use for the names of newly created threads.

public void
setThreadPriority(int threadPriority)

Set the priority of the threads that this factory creates.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

daemonback to summary
private boolean daemon
threadCountback to summary
private final AtomicInteger threadCount
threadGroupback to summary
private ThreadGroup threadGroup
Annotations
@Nullable
threadNamePrefixback to summary
private String threadNamePrefix
threadPriorityback to summary
private int threadPriority

Constructor Detail

CustomizableThreadCreatorback to summary
public CustomizableThreadCreator()

Create a new CustomizableThreadCreator with default thread name prefix.

CustomizableThreadCreatorback to summary
public CustomizableThreadCreator(String threadNamePrefix)

Create a new CustomizableThreadCreator with the given thread name prefix.

Parameters
threadNamePrefix:String

the prefix to use for the names of newly created threads

Method Detail

createThreadback to summary
public Thread createThread(Runnable runnable)

Template method for the creation of a new Thread.

The default implementation creates a new Thread for the given Runnable, applying an appropriate thread name.

Parameters
runnable:Runnable

the Runnable to execute

See Also
nextThreadName()
getDefaultThreadNamePrefixback to summary
protected String getDefaultThreadNamePrefix()

Build the default thread name prefix for this factory.

Returns:String

the default thread name prefix (never null)

getThreadGroupback to summary
public ThreadGroup getThreadGroup()

Return the thread group that threads should be created in (or null for the default group).

Annotations
@Nullable
getThreadNamePrefixback to summary
public String getThreadNamePrefix()

Return the thread name prefix to use for the names of newly created threads.

getThreadPriorityback to summary
public int getThreadPriority()

Return the priority of the threads that this factory creates.

isDaemonback to summary
public boolean isDaemon()

Return whether this factory should create daemon threads.

nextThreadNameback to summary
protected String nextThreadName()

Return the thread name to use for a newly created Thread.

The default implementation returns the specified thread name prefix with an increasing thread count appended: e.g. "SimpleAsyncTaskExecutor-0".

See Also
getThreadNamePrefix()
setDaemonback to summary
public void setDaemon(boolean daemon)

Set whether this factory is supposed to create daemon threads, just executing as long as the application itself is running.

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.

See Also
java.lang.Thread#setDaemon
setThreadGroupback to summary
public void setThreadGroup(ThreadGroup threadGroup)

Specify the thread group that threads should be created in.

See Also
setThreadGroupName
setThreadGroupNameback to summary
public void setThreadGroupName(String name)

Specify the name of the thread group that threads should be created in.

See Also
setThreadGroup
setThreadNamePrefixback to summary
public void setThreadNamePrefix(String threadNamePrefix)

Specify the prefix to use for the names of newly created threads. Default is "SimpleAsyncTaskExecutor-".

setThreadPriorityback to summary
public void setThreadPriority(int threadPriority)

Set the priority of the threads that this factory creates. Default is 5.

See Also
java.lang.Thread#NORM_PRIORITY