Skip to content

Commit

Permalink
Revised DefaultManagedAwareThreadFactory to make its non-JNDI fallbac…
Browse files Browse the repository at this point in the history
…k work

Issue: SPR-12830
(cherry picked from commit a3e5fbf)
  • Loading branch information
jhoeller committed Mar 20, 2015
1 parent 76649a4 commit 4446b5f
Showing 1 changed file with 17 additions and 11 deletions.
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,11 +32,14 @@
* for JSR-236's "java:comp/DefaultManagedThreadFactory" in a Java EE 7 environment,
* 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,
* simply using regular local threads otherwise - without conditional setup (like profiles).
* <p>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).
*
* <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
* @since 4.0
Expand All @@ -50,7 +53,7 @@ public class DefaultManagedAwareThreadFactory extends CustomizableThreadFactory

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

private ThreadFactory threadFactory = this;
private ThreadFactory threadFactory;


/**
Expand Down Expand Up @@ -98,20 +101,23 @@ public void afterPropertiesSet() throws NamingException {
}
catch (NamingException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to find [java:comp/DefaultManagedThreadFactory] in JNDI", ex);
}
if (logger.isInfoEnabled()) {
logger.info("Could not find default managed thread factory in JNDI - " +
"proceeding with default local thread factory");
logger.debug("Failed to retrieve [" + this.jndiName + "] from JNDI", ex);
}
logger.info("Could not find default managed thread factory in JNDI - " +
"proceeding with default local thread factory");
}
}
}


@Override
public Thread newThread(Runnable runnable) {
return this.threadFactory.newThread(runnable);
if (this.threadFactory != null) {
return this.threadFactory.newThread(runnable);
}
else {
return super.newThread(runnable);
}
}

}

0 comments on commit 4446b5f

Please sign in to comment.