Skip to content

DefaultManagedTaskExecutor throws java.lang.UnsupportedOperationException: isShutdown when rejecting tasks #34514

Closed
@DavidCerny2737

Description

@DavidCerny2737

I migrated old SpringBoot application running on Websphere Application Server to SpringBoot 3.2.5 running on WebSphere Liberty and I have encountered an issue with DefaultManagedTaskExecutor. I am connecting DefaultManagedTaskExecutor to jndi managedExecutorService defined on Liberty server:

Bean definition:

@Bean(name = "appTaskExecutor")    
@Primary    
    TaskExecutor appJndiTaskExecutor() {
        DefaultManagedTaskExecutor executor = new DefaultManagedTaskExecutor();
        executor.setResourceRef(true);
        executor.setJndiName("concurrent/appTask");
        return executor;
    }

server.xml

<managedExecutorService jndiName="concurrent/appTask">    
    <concurrencyPolicy max="2" maxQueueSize="5" runIfQueueFull="false" maxWaitForEnqueue="0" />    
</managedExecutorService>

I am then using appTaskExecutor in @Async annotation to run periodically scheduled async task. Problem happens when managedExecutorService task queue gets full and starts to reject new tasks. We are handeling such case with our logic triggering on TaskRejectedException throwing from TaskExecutorAdapter. Unfortunatelly this exception will be never thrown, indead we are expiriencing this:

java.lang.IllegalStateException: java.lang.UnsupportedOperationException: isShutdown
	at com.ibm.ws.concurrent.internal.ManagedExecutorServiceImpl.isShutdown(ManagedExecutorServiceImpl.java:710) ~[?:?]
	at org.springframework.core.task.TaskRejectedException.executorDescription(TaskRejectedException.java:72) ~[spring-core-6.1.6.jar:6.1.6]
	at org.springframework.core.task.TaskRejectedException.<init>(TaskRejectedException.java:66) ~[spring-core-6.1.6.jar:6.1.6]
	at org.springframework.core.task.support.TaskExecutorAdapter.submit(TaskExecutorAdapter.java:132) ~[spring-core-6.1.6.jar:6.1.6]
	at org.springframework.scheduling.concurrent.ConcurrentTaskExecutor$ManagedTaskExecutorAdapter.submit(ConcurrentTaskExecutor.java:221) ~[spring-context-6.1.6.jar:6.1.6]
	at org.springframework.scheduling.concurrent.ConcurrentTaskExecutor.submit(ConcurrentTaskExecutor.java:172) ~[spring-context-6.1.6.jar:6.1.6]
	at org.springframework.aop.interceptor.AsyncExecutionAspectSupport.$sw$original$doSubmit$m32m8m3(AsyncExecutionAspectSupport.java:297) ~[spring-aop-6.1.6.jar:6.1.6]
...

The problem lies in impelmentation of TaskRejectedException in executorDescription method method where executorService.isShutdown() gets called which is illegal in jakarta concurrent specification - chapter 3.1.6.1 in case when executorService is not managed by application itself but it is managed on server:

The lifecycle of a ManagedExecutorService is managed by an application server. All lifecycle operations on the ManagedExecutorService interface will throw a java.lang.IllegalStateException exception. This includes the following methods that are defined in the java.util.concurrent.ExecutorService interface: awaitTermination(), isShutdown(), isTerminated(), shutdown(), and shutdownNow().

It looks like this behaviour is part of jakarta concurrent specification going all the way back to the first edition of concurrency utilities for Java EE.. I have discussed this topic on StackOverflow and accepted workaround by using JndiObjectFactoryBean exposing only Executor interface via proxy to ConcurrentTaskExecutor, but it is still a workaround. In open liberty ManagedExecutorServiceImpm can be seen isShutdown() implementation and it follows jakarta concurrency specification. To be frank I am not sure what would be the right thing to fix this. In StackOverflow discussion came up an idea to open feature request on jakarta concurrency for a new version specification, but first I would like to open this topic here.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions