public class DefaultManagedAwareThreadFactory extends CustomizableThreadFactory implements InitializingBean
CustomizableThreadFactory
, performing a default lookup
for JSR-236's "java:comp/DefaultManagedThreadFactory" in a Java EE 7 environment,
falling back to the local CustomizableThreadFactory
setup 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
ThreadFactory
that can be found in JNDI. Therefore,
the default JNDI name "java:comp/DefaultManagedThreadFactory" can be customized
through the "jndiName"
bean property.
Constructor and Description |
---|
DefaultManagedAwareThreadFactory() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by the containing
BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware , ApplicationContextAware etc. |
java.lang.Thread |
newThread(java.lang.Runnable runnable) |
void |
setJndiEnvironment(java.util.Properties jndiEnvironment)
Set the JNDI environment to use for JNDI lookups.
|
void |
setJndiName(java.lang.String jndiName)
Specify a JNDI name of the
ThreadFactory to delegate to,
replacing the default JNDI name "java:comp/DefaultManagedThreadFactory". |
void |
setJndiTemplate(JndiTemplate jndiTemplate)
Set the JNDI template to use for JNDI lookups.
|
void |
setResourceRef(boolean resourceRef)
Set whether the lookup occurs in a J2EE container, i.e.
|
createThread, getDefaultThreadNamePrefix, getThreadGroup, getThreadNamePrefix, getThreadPriority, isDaemon, nextThreadName, setDaemon, setThreadGroup, setThreadGroupName, setThreadNamePrefix, setThreadPriority
protected final Log logger
public void setJndiTemplate(JndiTemplate jndiTemplate)
public void setJndiEnvironment(java.util.Properties jndiEnvironment)
public void setResourceRef(boolean resourceRef)
public void setJndiName(java.lang.String jndiName)
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".
setResourceRef(boolean)
public void afterPropertiesSet() throws javax.naming.NamingException
InitializingBean
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.
afterPropertiesSet
in interface InitializingBean
javax.naming.NamingException
public java.lang.Thread newThread(java.lang.Runnable runnable)
newThread
in interface java.util.concurrent.ThreadFactory
newThread
in class CustomizableThreadFactory