Class DefaultManagedAwareThreadFactory
- java.lang.Object
- org.springframework.util.CustomizableThreadCreator
- org.springframework.scheduling.concurrent.CustomizableThreadFactory
- org.springframework.scheduling.concurrent.DefaultManagedAwareThreadFactory
- All Implemented Interfaces:
Serializable,ThreadFactory,InitializingBean
public class DefaultManagedAwareThreadFactory extends CustomizableThreadFactory implements InitializingBean
JNDI-based variant ofCustomizableThreadFactory, performing a default lookup for JSR-236's "java:comp/DefaultManagedThreadFactory" in a Java EE 7 environment, falling back to the localCustomizableThreadFactorysetup if not found.This is a convenient way to use managed threads when running in a Java EE 7 environment, simply using regular local threads otherwise - without conditional setup (i.e. without profiles).
Note: This class is not strictly JSR-236 based; it can work with any regular
ThreadFactorythat can be found in JNDI. Therefore, the default JNDI name "java:comp/DefaultManagedThreadFactory" can be customized through the"jndiName"bean property.- Since:
- 4.0
- Author:
- Juergen Hoeller
- See Also:
- Serialized Form
Constructor Summary
Constructors Constructor Description DefaultManagedAwareThreadFactory()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.ThreadnewThread(Runnable runnable)voidsetJndiEnvironment(Properties jndiEnvironment)Set the JNDI environment to use for JNDI lookups.voidsetJndiName(String jndiName)Specify a JNDI name of theThreadFactoryto delegate to, replacing the default JNDI name "java:comp/DefaultManagedThreadFactory".voidsetJndiTemplate(JndiTemplate jndiTemplate)Set the JNDI template to use for JNDI lookups.voidsetResourceRef(boolean resourceRef)Set whether the lookup occurs in a J2EE container, i.e.Methods inherited from class org.springframework.util.CustomizableThreadCreator
createThread, getDefaultThreadNamePrefix, getThreadGroup, getThreadNamePrefix, getThreadPriority, isDaemon, nextThreadName, setDaemon, setThreadGroup, setThreadGroupName, setThreadNamePrefix, setThreadPriority
Constructor Detail
DefaultManagedAwareThreadFactory
public DefaultManagedAwareThreadFactory()
Method Detail
setJndiTemplate
public void setJndiTemplate(JndiTemplate jndiTemplate)
Set the JNDI template to use for JNDI lookups.
setJndiEnvironment
public void setJndiEnvironment(Properties jndiEnvironment)
Set the JNDI environment to use for JNDI lookups.
setResourceRef
public void setResourceRef(boolean resourceRef)
Set whether the lookup occurs in a J2EE container, i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it. PersistenceAnnotationBeanPostProcessor's default is "true".
setJndiName
public void setJndiName(String jndiName)
Specify a JNDI name of theThreadFactoryto delegate to, replacing the default JNDI name "java:comp/DefaultManagedThreadFactory".This can either be a fully qualified JNDI name, or the JNDI name relative to the current environment naming context if "resourceRef" is set to "true".
- See Also:
setResourceRef(boolean)
afterPropertiesSet
public void afterPropertiesSet() throws NamingException
Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSetin interfaceInitializingBean- Throws:
NamingException
newThread
public Thread newThread(Runnable runnable)
- Specified by:
newThreadin interfaceThreadFactory- Overrides:
newThreadin classCustomizableThreadFactory