|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
* Copyright 2002-2015 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -32,11 +32,14 @@ import org.springframework.jndi.JndiTemplate; |
|
|
|
* for JSR-236's "java:comp/DefaultManagedThreadFactory" in a Java EE 7 environment, |
|
|
|
* for JSR-236's "java:comp/DefaultManagedThreadFactory" in a Java EE 7 environment, |
|
|
|
* falling back to the local {@link CustomizableThreadFactory} setup if not found. |
|
|
|
* falling back to the local {@link CustomizableThreadFactory} setup if not found. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>This is a convenient way to use managed threads when running in a Java EE 7 environment, |
|
|
|
* <p>This is a convenient way to use managed threads when running in a Java EE 7 |
|
|
|
* simply using regular local threads otherwise - without conditional setup (like profiles). |
|
|
|
* environment, simply using regular local threads otherwise - without conditional |
|
|
|
|
|
|
|
* setup (i.e. without profiles). |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>Note: This class is not strictly JSR-236 based; it can work with any regular |
|
|
|
* <p>Note: This class is not strictly JSR-236 based; it can work with any regular |
|
|
|
* {@link java.util.concurrent.ThreadFactory} that can be found in JNDI. |
|
|
|
* {@link java.util.concurrent.ThreadFactory} that can be found in JNDI. Therefore, |
|
|
|
|
|
|
|
* the default JNDI name "java:comp/DefaultManagedThreadFactory" can be customized |
|
|
|
|
|
|
|
* through the {@link #setJndiName "jndiName"} bean property. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @since 4.0 |
|
|
|
* @since 4.0 |
|
|
|
@ -50,7 +53,7 @@ public class DefaultManagedAwareThreadFactory extends CustomizableThreadFactory |
|
|
|
|
|
|
|
|
|
|
|
private String jndiName = "java:comp/DefaultManagedThreadFactory"; |
|
|
|
private String jndiName = "java:comp/DefaultManagedThreadFactory"; |
|
|
|
|
|
|
|
|
|
|
|
private ThreadFactory threadFactory = this; |
|
|
|
private ThreadFactory threadFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -98,20 +101,23 @@ public class DefaultManagedAwareThreadFactory extends CustomizableThreadFactory |
|
|
|
} |
|
|
|
} |
|
|
|
catch (NamingException ex) { |
|
|
|
catch (NamingException ex) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
logger.debug("Failed to find [java:comp/DefaultManagedThreadFactory] in JNDI", ex); |
|
|
|
logger.debug("Failed to retrieve [" + this.jndiName + "] from JNDI", ex); |
|
|
|
} |
|
|
|
} |
|
|
|
if (logger.isInfoEnabled()) { |
|
|
|
|
|
|
|
logger.info("Could not find default managed thread factory in JNDI - " + |
|
|
|
logger.info("Could not find default managed thread factory in JNDI - " + |
|
|
|
"proceeding with default local thread factory"); |
|
|
|
"proceeding with default local thread factory"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Thread newThread(Runnable runnable) { |
|
|
|
public Thread newThread(Runnable runnable) { |
|
|
|
|
|
|
|
if (this.threadFactory != null) { |
|
|
|
return this.threadFactory.newThread(runnable); |
|
|
|
return this.threadFactory.newThread(runnable); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
return super.newThread(runnable); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|