Spring Framework

org.springframework.util
Class CustomizableThreadCreator

java.lang.Object
  extended by org.springframework.util.CustomizableThreadCreator
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
CustomizableThreadFactory, CustomizableThreadFactory, SimpleAsyncTaskExecutor

public class CustomizableThreadCreator
extends java.lang.Object
implements java.io.Serializable

Simple customizable helper class for creating threads. Provides various bean properties, such as thread name prefix, thread priority, etc.

Serves as base class for thread factories such as CustomizableThreadFactory.

Since:
2.0.3
Author:
Juergen Hoeller
See Also:
CustomizableThreadFactory, Serialized Form

Constructor Summary
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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomizableThreadCreator

public CustomizableThreadCreator()
Create a new CustomizableThreadCreator with default thread name prefix.


CustomizableThreadCreator

public CustomizableThreadCreator(java.lang.String threadNamePrefix)
Create a new CustomizableThreadCreator with the given thread name prefix.

Parameters:
threadNamePrefix - the prefix to use for the names of newly created threads
Method Detail

setThreadNamePrefix

public void setThreadNamePrefix(java.lang.String threadNamePrefix)
Specify the prefix to use for the names of newly created threads. Default is "SimpleAsyncTaskExecutor-".


getThreadNamePrefix

public java.lang.String getThreadNamePrefix()
Return the thread name prefix to use for the names of newly created threads.


setThreadPriority

public void setThreadPriority(int threadPriority)
Set the priority of the threads that this factory creates. Default is 5.

See Also:
Thread.NORM_PRIORITY

getThreadPriority

public int getThreadPriority()
Return the priority of the threads that this factory creates.


setDaemon

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.

See Also:
Thread.setDaemon(boolean)

isDaemon

public boolean isDaemon()
Return whether this factory should create daemon threads.


setThreadGroupName

public void setThreadGroupName(java.lang.String name)
Specify the name of the thread group that threads should be created in.

See Also:
setThreadGroup(java.lang.ThreadGroup)

setThreadGroup

public void setThreadGroup(java.lang.ThreadGroup threadGroup)
Specify the thread group that threads should be created in.

See Also:
setThreadGroupName(java.lang.String)

getThreadGroup

public java.lang.ThreadGroup getThreadGroup()
Return the thread group that threads should be created in (or null) for the default group.


createThread

public java.lang.Thread createThread(java.lang.Runnable runnable)
Template method for the creation of a Thread.

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

Parameters:
runnable - the Runnable to execute
See Also:
nextThreadName()

nextThreadName

protected java.lang.String nextThreadName()
Return the thread name to use for a newly created thread.

Default implementation returns the specified thread name prefix with an increasing thread count appended: for example, "SimpleAsyncTaskExecutor-0".

See Also:
getThreadNamePrefix()

getDefaultThreadNamePrefix

protected java.lang.String getDefaultThreadNamePrefix()
Build the default thread name prefix for this factory.

Returns:
the default thread name prefix (never null)

Spring Framework