org.springframework.scheduling.concurrent

## 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 of `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 (like profiles).

  Note: This class is not strictly JSR-236 based; it can work with any regular `ThreadFactory` that can be found in JNDI.

  Since:
    4.0
  Author:
    Juergen Hoeller
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Log` | `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultManagedAwareThreadFactory()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()` Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
    `Thread` | `newThread(Runnable runnable)`
    `void` | `setJndiEnvironment(Properties jndiEnvironment)` Set the JNDI environment to use for JNDI lookups.
    `void` | `setJndiName(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.

    - ### Methods inherited from class org.springframework.util.CustomizableThreadCreator

      `createThread, getDefaultThreadNamePrefix, getThreadGroup, getThreadNamePrefix, getThreadPriority, isDaemon, nextThreadName, setDaemon, setThreadGroup, setThreadGroupName, setThreadNamePrefix, setThreadPriority`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### logger

          protected final Log logger

  - ### Constructor Detail

    - #### DefaultManagedAwareThreadFactory

          public DefaultManagedAwareThreadFactory()

  - ### Method Detail

    - #### setJndiTemplate

          public void setJndiTemplate(JndiTemplate jndiTemplate)

      Set the JNDI template to use for JNDI lookups.
      See Also:
        `JndiAccessor.setJndiTemplate(org.springframework.jndi.JndiTemplate)`

    - #### setJndiEnvironment

          public void setJndiEnvironment(Properties jndiEnvironment)

      Set the JNDI environment to use for JNDI lookups.
      See Also:
        `JndiAccessor.setJndiEnvironment(java.util.Properties)`

    - #### 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".
      See Also:
        `JndiLocatorSupport.setResourceRef(boolean)`

    - #### setJndiName

          public void setJndiName(String jndiName)

      Specify a JNDI name of the `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(boolean)`

    - #### afterPropertiesSet

          public void afterPropertiesSet()
                                  throws NamingException

      Description copied from interface: `InitializingBean`
      Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

      This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

      Specified by:
        `afterPropertiesSet` in interface `InitializingBean`
      Throws:
        `NamingException`

    - #### newThread

          public Thread newThread(Runnable runnable)

      Specified by:
        `newThread` in interface `ThreadFactory`
      Overrides:
        `newThread` in class `CustomizableThreadFactory`