Class DefaultManagedAwareThreadFactory

  • All Implemented Interfaces:, java.util.concurrent.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 (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.

    Juergen Hoeller
    See Also:
    Serialized Form
    • Field Detail

      • logger

        protected final Log logger
    • Constructor Detail

      • DefaultManagedAwareThreadFactory

        public DefaultManagedAwareThreadFactory()
    • Method Detail

      • setResourceRef

        public void setResourceRef(boolean resourceRef)
        Set whether the lookup occurs in a Java 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:
      • setJndiName

        public void setJndiName(java.lang.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:
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws javax.naming.NamingException
        Description copied from interface: InitializingBean
        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.

        Specified by:
        afterPropertiesSet in interface InitializingBean
      • newThread

        public java.lang.Thread newThread(java.lang.Runnable runnable)
        Specified by:
        newThread in interface java.util.concurrent.ThreadFactory
        newThread in class CustomizableThreadFactory