Skip to content

Commit a3e5fbf

Browse files
committed
Revised DefaultManagedAwareThreadFactory to make its non-JNDI fallback work
Issue: SPR-12830
1 parent ce68c4d commit a3e5fbf

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedAwareThreadFactory.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,11 +32,14 @@
3232
* for JSR-236's "java:comp/DefaultManagedThreadFactory" in a Java EE 7 environment,
3333
* falling back to the local {@link CustomizableThreadFactory} setup if not found.
3434
*
35-
* <p>This is a convenient way to use managed threads when running in a Java EE 7 environment,
36-
* simply using regular local threads otherwise - without conditional setup (like profiles).
35+
* <p>This is a convenient way to use managed threads when running in a Java EE 7
36+
* environment, simply using regular local threads otherwise - without conditional
37+
* setup (i.e. without profiles).
3738
*
3839
* <p>Note: This class is not strictly JSR-236 based; it can work with any regular
39-
* {@link java.util.concurrent.ThreadFactory} that can be found in JNDI.
40+
* {@link java.util.concurrent.ThreadFactory} that can be found in JNDI. Therefore,
41+
* the default JNDI name "java:comp/DefaultManagedThreadFactory" can be customized
42+
* through the {@link #setJndiName "jndiName"} bean property.
4043
*
4144
* @author Juergen Hoeller
4245
* @since 4.0
@@ -50,7 +53,7 @@ public class DefaultManagedAwareThreadFactory extends CustomizableThreadFactory
5053

5154
private String jndiName = "java:comp/DefaultManagedThreadFactory";
5255

53-
private ThreadFactory threadFactory = this;
56+
private ThreadFactory threadFactory;
5457

5558

5659
/**
@@ -98,20 +101,23 @@ public void afterPropertiesSet() throws NamingException {
98101
}
99102
catch (NamingException ex) {
100103
if (logger.isDebugEnabled()) {
101-
logger.debug("Failed to find [java:comp/DefaultManagedThreadFactory] in JNDI", ex);
102-
}
103-
if (logger.isInfoEnabled()) {
104-
logger.info("Could not find default managed thread factory in JNDI - " +
105-
"proceeding with default local thread factory");
104+
logger.debug("Failed to retrieve [" + this.jndiName + "] from JNDI", ex);
106105
}
106+
logger.info("Could not find default managed thread factory in JNDI - " +
107+
"proceeding with default local thread factory");
107108
}
108109
}
109110
}
110111

111112

112113
@Override
113114
public Thread newThread(Runnable runnable) {
114-
return this.threadFactory.newThread(runnable);
115+
if (this.threadFactory != null) {
116+
return this.threadFactory.newThread(runnable);
117+
}
118+
else {
119+
return super.newThread(runnable);
120+
}
115121
}
116122

117123
}

0 commit comments

Comments
 (0)