question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Distributed scheduled executor service with Spring Boot

See original GitHub issue

Hello 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
alevikzscommented, Jan 28, 2020

Thanks, I have added destroyMethod = "" argument to @Bean annotation.

0reactions
CarryWllcommented, Sep 27, 2022

Please how did you solve this problem in the end?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found