Top Description Fields Constructors Methods
org.springframework.scheduling.concurrent

public Class DefaultManagedAwareThreadFactory

extends CustomizableThreadFactory
implements InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean
Annotations
@SuppressWarnings:serial
Imports
java.util.Properties, java.util.concurrent.ThreadFactory, javax.naming.NamingException, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.factory.InitializingBean, org.springframework.jndi.JndiLocatorDelegate, .JndiTemplate, org.springframework.lang.Nullable

JNDI-based variant of CustomizableThreadFactory, performing a default lookup for JSR-236's "java:comp/DefaultManagedThreadFactory" in a Jakarta EE environment, falling back to the local CustomizableThreadFactory setup if not found.

This is a convenient way to use managed threads when running in a Jakarta EE 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 java.util.concurrent.ThreadFactory that can be found in JNDI. Therefore, the default JNDI name "java:comp/DefaultManagedThreadFactory" can be customized through the "jndiName" bean property.

Author
Juergen Hoeller
Since
4.0

Field Summary

Modifier and TypeField and Description
private final JndiLocatorDelegate
private String
protected final Log
private ThreadFactory

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

public Thread
newThread(Runnable
a runnable to be executed by new thread instance
runnable
)

Overrides org.springframework.scheduling.concurrent.CustomizableThreadFactory.newThread.

Implements java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

public void
setJndiEnvironment(Properties jndiEnvironment)

Set the JNDI environment to use for JNDI lookups.

public void
setJndiName(String jndiName)

Specify a JNDI name of the java.util.concurrent.ThreadFactory to delegate to, replacing the default JNDI name "java:comp/DefaultManagedThreadFactory".

public void
setJndiTemplate(JndiTemplate jndiTemplate)

Set the JNDI template to use for JNDI lookups.

public void
setResourceRef(boolean resourceRef)

Set whether the lookup occurs in a Jakarta EE container, i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it.

Field Detail

jndiLocatorback to summary
private final JndiLocatorDelegate jndiLocator
jndiNameback to summary
private String jndiName
Annotations
@Nullable
loggerback to summary
protected final Log logger
threadFactoryback to summary
private ThreadFactory threadFactory
Annotations
@Nullable

Constructor Detail

DefaultManagedAwareThreadFactoryback to summary
public DefaultManagedAwareThreadFactory()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws NamingException

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

Annotations
@Override
newThreadback to summary
public Thread newThread(Runnable runnable)

Overrides org.springframework.scheduling.concurrent.CustomizableThreadFactory.newThread.

Implements java.util.concurrent.ThreadFactory.newThread.

Doc from java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

Parameters
runnable:Runnable

a runnable to be executed by new thread instance

Returns:Thread

constructed thread, or null if the request to create a thread is rejected

Annotations
@Override
setJndiEnvironmentback to summary
public void setJndiEnvironment(Properties jndiEnvironment)

Set the JNDI environment to use for JNDI lookups.

See Also
org.springframework.jndi.JndiAccessor#setJndiEnvironment
setJndiNameback to summary
public void setJndiName(String jndiName)

Specify a JNDI name of the java.util.concurrent.ThreadFactory to 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
setJndiTemplateback to summary
public void setJndiTemplate(JndiTemplate jndiTemplate)

Set the JNDI template to use for JNDI lookups.

See Also
org.springframework.jndi.JndiAccessor#setJndiTemplate
setResourceRefback to summary
public void setResourceRef(boolean resourceRef)

Set whether the lookup occurs in a Jakarta EE 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".

See Also
org.springframework.jndi.JndiLocatorSupport#setResourceRef