Distributed scheduled executor service with Spring Boot
See original GitHub issueHello there.
I try to use Redisson for schedule tasks in my Spring Boot application. And I have the next issue: after application restart with graceful shutdown - Redison scheduled executor service is in shutdown state, and all my tasks are rejected with exception
java.util.concurrent.RejectedExecutionException: Task rejected. ExecutorService is in shutdown state
Here is my code: I use Distributed scheduled executor service like a bean
@Configuration
public class RedissonScheduledExecutorConfig {
private static final String EXECUTOR_SERVICE_NAME = "rScheduledExecutor";
@Bean
public RScheduledExecutorService rScheduledExecutorService(
final RedissonClient redissonClient,
final BeanFactory beanFactory
) {
final WorkerOptions workerOptions = WorkerOptions.defaults().workers(1).beanFactory(beanFactory);
final ExecutorOptions executorOptions = ExecutorOptions.defaults()
.taskRetryInterval(0, TimeUnit.SECONDS);
final RScheduledExecutorService executorService = redissonClient
.getExecutorService(EXECUTOR_SERVICE_NAME, executorOptions);
executorService.registerWorkers(workerOptions);
return executorService;
}
}
Send the task to executor:
@RestController
@RequiredArgsConstructor
public final class TestController {
private final RScheduledExecutorService rScheduledExecutorService;
@GetMapping("/test")
public String test() {
final RScheduledFuture<?> rScheduledFuture = this.rScheduledExecutorService.schedule(
new RunnableTask(),
60,
TimeUnit.SECONDS
);
}
}
Task implementation:
public final class RunnableTask implements Runnable, Serializable {
private static final long serialVersionUID = 1L;
@Autowired
private transient MyService myService;
@Override
public void run() {
this.myService.sendEmail();
}
}
I use spring boot version - 2.1.7.RELEASE, and redisson-spring-boot-starter
with version 3.11.5
Thank you for any help!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top Results From Across the Web
27. Task Execution and Scheduling - Spring
The Spring Framework provides abstractions for asynchronous execution and scheduling of tasks with the TaskExecutor and TaskScheduler interfaces, ...
Read more >A Guide to the Java ExecutorService - Baeldung
An intro and guide to the ExecutorService framework provided by the JDK - which simplifies the execution of tasks in asynchronous mode.
Read more >SpringBoot With Redisson's Distributed Task Engine - LinkedIn
This post is talking about Redis based distributed task engine: Redisson's Remote Executor Service and it's integration with SpringBoot.
Read more >Hazelcast Distributed Execution with Spring - Java Code Geeks
Hazelcast Distributed Executor Service feature is a distributed implementation of java.util.concurrent.ExecutorService. It allows to execute ...
Read more >Hazelcast Distributed Execution with Spring - DZone
The ExecutorService feature had come with Java 5 and is under the java.util.concurrent package. It extends the Executor interface and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks, I have added
destroyMethod = ""
argument to@Bean
annotation.Please how did you solve this problem in the end?