From 49758a2a96261d827c9f448af7de157116e547fb Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 2 Nov 2013 20:14:02 +0100 Subject: [PATCH] Added convenience classes for typical JSR-236 setup in a Java EE 7 environment Introduced DefaultManagedTaskExecutor, DefaultManagedTaskScheduler and DefaultManagedAwareThreadFactory classes, revised related javadoc, and deprecated unsupported JBossWorkManagerTaskExecutor in favor of JSR-236 setup on WildFly 8. Issue: SPR-8195 --- .../commonj/WorkManagerTaskExecutor.java | 43 ++----- .../concurrent/ConcurrentTaskExecutor.java | 14 ++- .../concurrent/ConcurrentTaskScheduler.java | 14 ++- .../DefaultManagedAwareThreadFactory.java | 116 ++++++++++++++++++ .../DefaultManagedTaskExecutor.java | 91 ++++++++++++++ .../DefaultManagedTaskScheduler.java | 93 ++++++++++++++ .../ExecutorConfigurationSupport.java | 6 +- .../GlassFishWorkManagerTaskExecutor.java | 12 +- .../jboss/JBossWorkManagerTaskExecutor.java | 11 +- .../jca/work/jboss/JBossWorkManagerUtils.java | 7 +- 10 files changed, 356 insertions(+), 51 deletions(-) create mode 100644 spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedAwareThreadFactory.java create mode 100644 spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedTaskExecutor.java create mode 100644 spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedTaskScheduler.java diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/commonj/WorkManagerTaskExecutor.java b/spring-context-support/src/main/java/org/springframework/scheduling/commonj/WorkManagerTaskExecutor.java index 2c9ce17a49b..e335f00d329 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/commonj/WorkManagerTaskExecutor.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/commonj/WorkManagerTaskExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -17,10 +17,9 @@ package org.springframework.scheduling.commonj; import java.util.Collection; +import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; -import java.util.concurrent.Callable; - import javax.naming.NamingException; import commonj.work.Work; @@ -53,17 +52,9 @@ import org.springframework.util.Assert; *

The CommonJ WorkManager will usually be retrieved from the application * server's JNDI environment, as defined in the server's management console. * - *

Note: At the time of this writing, the CommonJ WorkManager facility - * is only supported on IBM WebSphere 6.0+ and BEA WebLogic 9.0+, - * despite being such a crucial API for an application server. - * (There is a similar facility available on WebSphere 5.1 Enterprise, - * though, which we will discuss below.) - * - *

On JBoss and GlassFish, a similar facility is available through - * the JCA WorkManager. See the - * {@link org.springframework.jca.work.jboss.JBossWorkManagerTaskExecutor} - * {@link org.springframework.jca.work.glassfish.GlassFishWorkManagerTaskExecutor} - * classes which are the direct equivalent of this CommonJ adapter class. + *

Note: On the upcoming EE 7 compliant versions of WebLogic and WebSphere, a + * {@link org.springframework.scheduling.concurrent.DefaultManagedTaskExecutor} + * should be preferred, following JSR-236 support in Java EE 7. * * @author Juergen Hoeller * @since 2.0 @@ -80,8 +71,7 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport /** * Specify the CommonJ WorkManager to delegate to. - *

Alternatively, you can also specify the JNDI name - * of the target WorkManager. + *

Alternatively, you can also specify the JNDI name of the target WorkManager. * @see #setWorkManagerName */ public void setWorkManager(WorkManager workManager) { @@ -90,9 +80,8 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport /** * Set the JNDI name of the CommonJ WorkManager. - *

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". + *

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 #setWorkManager * @see #setResourceRef */ @@ -177,30 +166,22 @@ public class WorkManagerTaskExecutor extends JndiLocatorSupport //------------------------------------------------------------------------- @Override - public WorkItem schedule(Work work) - throws WorkException, IllegalArgumentException { - + public WorkItem schedule(Work work) throws WorkException, IllegalArgumentException { return this.workManager.schedule(work); } @Override - public WorkItem schedule(Work work, WorkListener workListener) - throws WorkException, IllegalArgumentException { - + public WorkItem schedule(Work work, WorkListener workListener) throws WorkException { return this.workManager.schedule(work, workListener); } @Override - public boolean waitForAll(Collection workItems, long timeout) - throws InterruptedException, IllegalArgumentException { - + public boolean waitForAll(Collection workItems, long timeout) throws InterruptedException { return this.workManager.waitForAll(workItems, timeout); } @Override - public Collection waitForAny(Collection workItems, long timeout) - throws InterruptedException, IllegalArgumentException { - + public Collection waitForAny(Collection workItems, long timeout) throws InterruptedException { return this.workManager.waitForAny(workItems, timeout); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java index bb7ee45b56a..4f0a0ec8eb4 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java @@ -38,8 +38,9 @@ import org.springframework.util.ClassUtils; * *

Autodetects a JSR-236 {@link javax.enterprise.concurrent.ManagedExecutorService} * in order to expose {@link javax.enterprise.concurrent.ManagedTask} adapters for it, - * exposing a long-running hint based on {@link SchedulingAwareRunnable} and an - * identity name based on the given Runnable/Callable's {@code toString()}. + * exposing a long-running hint based on {@link SchedulingAwareRunnable} and an identity + * name based on the given Runnable/Callable's {@code toString()}. For JSR-236 style + * lookup in a Java EE 7 environment, consider using {@link DefaultManagedTaskExecutor}. * *

Note that there is a pre-built {@link ThreadPoolTaskExecutor} that allows * for defining a {@link java.util.concurrent.ThreadPoolExecutor} in bean style, @@ -53,21 +54,22 @@ import org.springframework.util.ClassUtils; * @see java.util.concurrent.ExecutorService * @see java.util.concurrent.ThreadPoolExecutor * @see java.util.concurrent.Executors + * @see DefaultManagedTaskExecutor * @see ThreadPoolTaskExecutor */ public class ConcurrentTaskExecutor implements SchedulingTaskExecutor { - private static Class managedExecutorService; + private static Class managedExecutorServiceClass; static { try { - managedExecutorService = ClassUtils.forName( + managedExecutorServiceClass = ClassUtils.forName( "javax.enterprise.concurrent.ManagedExecutorService", ConcurrentTaskScheduler.class.getClassLoader()); } catch (ClassNotFoundException ex) { // JSR-236 API not available... - managedExecutorService = null; + managedExecutorServiceClass = null; } } @@ -103,7 +105,7 @@ public class ConcurrentTaskExecutor implements SchedulingTaskExecutor { public final void setConcurrentExecutor(Executor concurrentExecutor) { if (concurrentExecutor != null) { this.concurrentExecutor = concurrentExecutor; - if (managedExecutorService != null && managedExecutorService.isInstance(concurrentExecutor)) { + if (managedExecutorServiceClass != null && managedExecutorServiceClass.isInstance(concurrentExecutor)) { this.adaptedExecutor = new ManagedTaskExecutorAdapter(concurrentExecutor); } else { diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java index e4f4dfd5176..e07d5b8ee21 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java @@ -44,7 +44,8 @@ import org.springframework.util.ErrorHandler; *

Autodetects a JSR-236 {@link javax.enterprise.concurrent.ManagedScheduledExecutorService} * in order to use it for trigger-based scheduling if possible, instead of Spring's * local trigger management which ends up delegating to regular delay-based scheduling - * against the {@code java.util.concurrent.ScheduledExecutorService} API. + * against the {@code java.util.concurrent.ScheduledExecutorService} API. For JSR-236 style + * lookup in a Java EE 7 environment, consider using {@link DefaultManagedTaskScheduler}. * *

Note that there is a pre-built {@link ThreadPoolTaskScheduler} that allows for * defining a {@link java.util.concurrent.ScheduledThreadPoolExecutor} in bean style, @@ -58,21 +59,22 @@ import org.springframework.util.ErrorHandler; * @see java.util.concurrent.ScheduledExecutorService * @see java.util.concurrent.ScheduledThreadPoolExecutor * @see java.util.concurrent.Executors + * @see DefaultManagedTaskScheduler * @see ThreadPoolTaskScheduler */ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements TaskScheduler { - private static Class managedScheduledExecutorService; + private static Class managedScheduledExecutorServiceClass; static { try { - managedScheduledExecutorService = ClassUtils.forName( + managedScheduledExecutorServiceClass = ClassUtils.forName( "javax.enterprise.concurrent.ManagedScheduledExecutorService", ConcurrentTaskScheduler.class.getClassLoader()); } catch (ClassNotFoundException ex) { // JSR-236 API not available... - managedScheduledExecutorService = null; + managedScheduledExecutorServiceClass = null; } } @@ -139,8 +141,8 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T public final void setScheduledExecutor(ScheduledExecutorService scheduledExecutor) { if (scheduledExecutor != null) { this.scheduledExecutor = scheduledExecutor; - this.enterpriseConcurrentScheduler = (managedScheduledExecutorService != null && - managedScheduledExecutorService.isInstance(scheduledExecutor)); + this.enterpriseConcurrentScheduler = (managedScheduledExecutorServiceClass != null && + managedScheduledExecutorServiceClass.isInstance(scheduledExecutor)); } else { this.scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedAwareThreadFactory.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedAwareThreadFactory.java new file mode 100644 index 00000000000..37af5d3fc76 --- /dev/null +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedAwareThreadFactory.java @@ -0,0 +1,116 @@ +/* + * Copyright 2002-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.scheduling.concurrent; + +import java.util.Properties; +import java.util.concurrent.ThreadFactory; +import javax.naming.NamingException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.jndi.JndiLocatorDelegate; +import org.springframework.jndi.JndiTemplate; + +/** + * JNDI-based variant of {@link CustomizableThreadFactory}, performing a default lookup + * for JSR-236's "java:comp/DefaultManagedThreadFactory" in a Java EE 7 environment, + * falling back to the local {@link 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 + * {@link java.util.concurrent.ThreadFactory} that can be found in JNDI. + * + * @author Juergen Hoeller + * @since 4.0 + */ +public class DefaultManagedAwareThreadFactory extends CustomizableThreadFactory implements InitializingBean { + + protected final Log logger = LogFactory.getLog(getClass()); + + private JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); + + private String jndiName = "java:comp/DefaultManagedThreadFactory"; + + private ThreadFactory threadFactory = this; + + + /** + * Set the JNDI template to use for JNDI lookups. + * @see org.springframework.jndi.JndiAccessor#setJndiTemplate + */ + public void setJndiTemplate(JndiTemplate jndiTemplate) { + this.jndiLocator.setJndiTemplate(jndiTemplate); + } + + /** + * Set the JNDI environment to use for JNDI lookups. + * @see org.springframework.jndi.JndiAccessor#setJndiEnvironment + */ + public void setJndiEnvironment(Properties jndiEnvironment) { + this.jndiLocator.setJndiEnvironment(jndiEnvironment); + } + + /** + * 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 org.springframework.jndi.JndiLocatorSupport#setResourceRef + */ + public void setResourceRef(boolean resourceRef) { + this.jndiLocator.setResourceRef(resourceRef); + } + + /** + * Specify a JNDI name of the {@link java.util.concurrent.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 #setResourceRef + */ + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + @Override + public void afterPropertiesSet() throws NamingException { + if (this.jndiName != null) { + try { + this.threadFactory = this.jndiLocator.lookup(this.jndiName, ThreadFactory.class); + } + 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"); + } + } + } + } + + + @Override + public Thread newThread(Runnable runnable) { + return this.threadFactory.newThread(runnable); + } + +} diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedTaskExecutor.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedTaskExecutor.java new file mode 100644 index 00000000000..1aad3a46a03 --- /dev/null +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedTaskExecutor.java @@ -0,0 +1,91 @@ +/* + * Copyright 2002-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.scheduling.concurrent; + +import java.util.Properties; +import java.util.concurrent.Executor; +import javax.naming.NamingException; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.jndi.JndiLocatorDelegate; +import org.springframework.jndi.JndiTemplate; + +/** + * JNDI-based variant of {@link ConcurrentTaskExecutor}, performing a default lookup for + * JSR-236's "java:comp/DefaultManagedExecutorService" in a Java EE 7 environment. + * + *

Note: This class is not strictly JSR-236 based; it can work with any regular + * {@link java.util.concurrent.Executor} that can be found in JNDI. + * The actual adapting to {@link javax.enterprise.concurrent.ManagedExecutorService} + * happens in the base class {@link ConcurrentTaskExecutor} itself. + * + * @author Juergen Hoeller + * @since 4.0 + */ +public class DefaultManagedTaskExecutor extends ConcurrentTaskExecutor implements InitializingBean { + + private JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); + + private String jndiName = "java:comp/DefaultManagedExecutorService"; + + + /** + * Set the JNDI template to use for JNDI lookups. + * @see org.springframework.jndi.JndiAccessor#setJndiTemplate + */ + public void setJndiTemplate(JndiTemplate jndiTemplate) { + this.jndiLocator.setJndiTemplate(jndiTemplate); + } + + /** + * Set the JNDI environment to use for JNDI lookups. + * @see org.springframework.jndi.JndiAccessor#setJndiEnvironment + */ + public void setJndiEnvironment(Properties jndiEnvironment) { + this.jndiLocator.setJndiEnvironment(jndiEnvironment); + } + + /** + * 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 org.springframework.jndi.JndiLocatorSupport#setResourceRef + */ + public void setResourceRef(boolean resourceRef) { + this.jndiLocator.setResourceRef(resourceRef); + } + + /** + * Specify a JNDI name of the {@link java.util.concurrent.Executor} to delegate to, + * replacing the default JNDI name "java:comp/DefaultManagedExecutorService". + *

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 #setConcurrentExecutor + * @see #setResourceRef + */ + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + @Override + public void afterPropertiesSet() throws NamingException { + if (this.jndiName != null) { + setConcurrentExecutor(this.jndiLocator.lookup(this.jndiName, Executor.class)); + } + } + +} diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedTaskScheduler.java new file mode 100644 index 00000000000..039a6a78000 --- /dev/null +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedTaskScheduler.java @@ -0,0 +1,93 @@ +/* + * Copyright 2002-2013 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.scheduling.concurrent; + +import java.util.Properties; +import java.util.concurrent.ScheduledExecutorService; +import javax.naming.NamingException; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.jndi.JndiLocatorDelegate; +import org.springframework.jndi.JndiTemplate; + +/** + * JNDI-based variant of {@link ConcurrentTaskScheduler}, performing a default lookup for + * JSR-236's "java:comp/DefaultManagedScheduledExecutorService" in a Java EE 7 environment. + * + *

Note: This class is not strictly JSR-236 based; it can work with any regular + * {@link java.util.concurrent.ScheduledExecutorService} that can be found in JNDI. + * The actual adapting to {@link javax.enterprise.concurrent.ManagedScheduledExecutorService} + * happens in the base class {@link ConcurrentTaskScheduler} itself. + * + * @author Juergen Hoeller + * @since 4.0 + */ +public class DefaultManagedTaskScheduler extends ConcurrentTaskScheduler implements InitializingBean { + + private JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); + + private String jndiName = "java:comp/DefaultManagedScheduledExecutorService"; + + + /** + * Set the JNDI template to use for JNDI lookups. + * @see org.springframework.jndi.JndiAccessor#setJndiTemplate + */ + public void setJndiTemplate(JndiTemplate jndiTemplate) { + this.jndiLocator.setJndiTemplate(jndiTemplate); + } + + /** + * Set the JNDI environment to use for JNDI lookups. + * @see org.springframework.jndi.JndiAccessor#setJndiEnvironment + */ + public void setJndiEnvironment(Properties jndiEnvironment) { + this.jndiLocator.setJndiEnvironment(jndiEnvironment); + } + + /** + * 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 org.springframework.jndi.JndiLocatorSupport#setResourceRef + */ + public void setResourceRef(boolean resourceRef) { + this.jndiLocator.setResourceRef(resourceRef); + } + + /** + * Specify a JNDI name of the {@link java.util.concurrent.Executor} to delegate to, + * replacing the default JNDI name "java:comp/DefaultManagedScheduledExecutorService". + *

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 #setConcurrentExecutor + * @see #setResourceRef + */ + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + @Override + public void afterPropertiesSet() throws NamingException { + if (this.jndiName != null) { + ScheduledExecutorService executor = this.jndiLocator.lookup(this.jndiName, ScheduledExecutorService.class); + setConcurrentExecutor(executor); + setScheduledExecutor(executor); + } + } + +} diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java index fa2ae75206c..a7ce5fb000c 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java @@ -67,10 +67,14 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac * Default is the underlying ExecutorService's default thread factory. *

In a Java EE 7 or other managed environment with JSR-236 support, * consider specifying a JNDI-located ManagedThreadFactory: by default, - * to be found at "java:comp/env/concurrent/tf/DefaultThreadFactory". + * to be found at "java:comp/DefaultManagedThreadFactory". * Use the "jee:jndi-lookup" namespace element in XML or the programmatic * {@link org.springframework.jndi.JndiLocatorDelegate} for convenient lookup. + * Alternatively, consider using Spring's {@link DefaultManagedAwareThreadFactory} + * with its fallback to local threads in case of no managed thread factory found. * @see java.util.concurrent.Executors#defaultThreadFactory() + * @see javax.enterprise.concurrent.ManagedThreadFactory + * @see DefaultManagedAwareThreadFactory */ public void setThreadFactory(ThreadFactory threadFactory) { this.threadFactory = (threadFactory != null ? threadFactory : this); diff --git a/spring-tx/src/main/java/org/springframework/jca/work/glassfish/GlassFishWorkManagerTaskExecutor.java b/spring-tx/src/main/java/org/springframework/jca/work/glassfish/GlassFishWorkManagerTaskExecutor.java index 431884514db..8d30efdbd28 100644 --- a/spring-tx/src/main/java/org/springframework/jca/work/glassfish/GlassFishWorkManagerTaskExecutor.java +++ b/spring-tx/src/main/java/org/springframework/jca/work/glassfish/GlassFishWorkManagerTaskExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -31,6 +31,10 @@ import org.springframework.util.ReflectionUtils; * {@link org.springframework.scheduling.commonj.WorkManagerTaskExecutor} * adapter for WebLogic and WebSphere. * + *

Note: On GlassFish 4 and higher, a + * {@link org.springframework.scheduling.concurrent.DefaultManagedTaskExecutor} + * should be preferred, following JSR-236 support in Java EE 7. + * * @author Juergen Hoeller * @since 2.5.2 */ @@ -43,12 +47,12 @@ public class GlassFishWorkManagerTaskExecutor extends WorkManagerTaskExecutor { public GlassFishWorkManagerTaskExecutor() { try { - Class wmf = getClass().getClassLoader().loadClass(WORK_MANAGER_FACTORY_CLASS); - this.getWorkManagerMethod = wmf.getMethod("getWorkManager", new Class[] {String.class}); + Class wmf = getClass().getClassLoader().loadClass(WORK_MANAGER_FACTORY_CLASS); + this.getWorkManagerMethod = wmf.getMethod("getWorkManager", String.class); } catch (Exception ex) { throw new IllegalStateException( - "Could not initialize GlassFishWorkManagerTaskExecutor because GlassFish API is not available: " + ex); + "Could not initialize GlassFishWorkManagerTaskExecutor because GlassFish API is not available", ex); } } diff --git a/spring-tx/src/main/java/org/springframework/jca/work/jboss/JBossWorkManagerTaskExecutor.java b/spring-tx/src/main/java/org/springframework/jca/work/jboss/JBossWorkManagerTaskExecutor.java index 5abb09231b8..be6b0c74e5d 100644 --- a/spring-tx/src/main/java/org/springframework/jca/work/jboss/JBossWorkManagerTaskExecutor.java +++ b/spring-tx/src/main/java/org/springframework/jca/work/jboss/JBossWorkManagerTaskExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2013 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. @@ -29,10 +29,19 @@ import org.springframework.jca.work.WorkManagerTaskExecutor; * {@link org.springframework.scheduling.commonj.WorkManagerTaskExecutor} * adapter for WebLogic and WebSphere. * + *

This class does not work on JBoss 7 or higher. There is no known + * immediate replacement, since JBoss does not want its JCA WorkManager + * to be exposed anymore. As of JBoss/WildFly 8, a + * {@link org.springframework.scheduling.concurrent.DefaultManagedTaskExecutor} + * may be used, following JSR-236 support in Java EE 7. + * * @author Juergen Hoeller * @since 2.5.2 * @see org.jboss.resource.work.JBossWorkManagerMBean + * @deprecated as of Spring 4.0, since there are no fully supported versions + * of JBoss that this class works with anymore */ +@Deprecated public class JBossWorkManagerTaskExecutor extends WorkManagerTaskExecutor { /** diff --git a/spring-tx/src/main/java/org/springframework/jca/work/jboss/JBossWorkManagerUtils.java b/spring-tx/src/main/java/org/springframework/jca/work/jboss/JBossWorkManagerUtils.java index 7c2757b600c..cc141b2e2ca 100644 --- a/spring-tx/src/main/java/org/springframework/jca/work/jboss/JBossWorkManagerUtils.java +++ b/spring-tx/src/main/java/org/springframework/jca/work/jboss/JBossWorkManagerUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2013 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. @@ -31,7 +31,10 @@ import org.springframework.util.Assert; * * @author Juergen Hoeller * @since 2.5.2 + * @deprecated as of Spring 4.0, since there are no fully supported versions + * of JBoss that this class works with anymore */ +@Deprecated public abstract class JBossWorkManagerUtils { private static final String JBOSS_WORK_MANAGER_MBEAN_CLASS_NAME = "org.jboss.resource.work.JBossWorkManagerMBean"; @@ -69,7 +72,7 @@ public abstract class JBossWorkManagerUtils { } catch (Exception ex) { throw new IllegalStateException( - "Could not initialize JBossWorkManagerTaskExecutor because JBoss API is not available: " + ex); + "Could not initialize JBossWorkManagerTaskExecutor because JBoss API is not available", ex); } }