4

I am using redisson ExecutorService in kotlin,but an exception occur like this, "java.util.concurrent.RejectedExecutionException: Task rejected. ExecutorService is in shutdown state".

class RunnableTask : Runnable ,Serializable{
   private val redissonClient: RedissonClient? = null
   private var param: Long=0

   override fun run() {
      val atomic = redissonClient!!.getAtomicLong("myAtomic")
      atomic.addAndGet(param)
      }

 }

fun main(args: Array<String>) {
  val config = Config()
  config.useSingleServer()
      .setAddress("redis://127.0.0.1:6379")
  val redisson = Redisson.create(config)

  val nodeConfig =   RedissonNodeConfig(config)   

  nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("myExecutor", 1))
  val node = RedissonNode.create(nodeConfig)
  node.start()
  val e = redisson.getExecutorService("myExecutor")
  e.execute(  RunnableTask())
  e.shutdown()
  node.shutdown()

}

I use redisson 3.11.5.

Azdy
  • 170
  • 9

2 Answers2

1

What is working for me:

val e = redisson.getExecutorService("myExecutor")
if (e.isShutdown()) {
    e.delete()
}

I assume the remote executor gets into shutdown state when there is no worker connected to process the tasks.

plajko
  • 381
  • 2
  • 9
  • it doesn't get into shutdown state until you call this method. After shutdown you need to delete executorService if you want to use it again. – Nikita Koksharov Feb 24 '23 at 05:29
0

ExecutorServiceExamples and SchedulerServiceExamples was fixed.

You need to delete ExecutorService once it got into shutdown state. This is why you always get the error on a second run.

Nikita Koksharov
  • 10,283
  • 1
  • 62
  • 71
  • https://github.com/redisson/redisson-examples/commit/b312d855a79a95509cee9c733d2566e7fd2594c2 Here is a commit of the change. It would be useful to explain with code in your answer... – Mark Feb 24 '23 at 10:59
  • @Mark `You need to delete ExecutorService once it got into shutdown state` - this is the explanation. flushAll cleans the database – Nikita Koksharov Feb 26 '23 at 06:00