From b76c4e6aa94fb3aa6616d50e4997c3ec18d53518 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 14 Feb 2024 12:38:30 +0700 Subject: [PATCH] Some semantic fixes to carriedexecutor --- gradle.properties | 2 +- .../kommons/util/CarriedExecutor.kt | 18 +++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4cd379a..a3318c9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ kotlin.code.style=official specifyKotlinAsDependency=false projectGroup=ru.dbotthepony.kommons -projectVersion=2.2.0 +projectVersion=2.2.1 guavaDepVersion=33.0.0 gsonDepVersion=2.8.9 diff --git a/src/main/kotlin/ru/dbotthepony/kommons/util/CarriedExecutor.kt b/src/main/kotlin/ru/dbotthepony/kommons/util/CarriedExecutor.kt index a1663f5..9a8fcbd 100644 --- a/src/main/kotlin/ru/dbotthepony/kommons/util/CarriedExecutor.kt +++ b/src/main/kotlin/ru/dbotthepony/kommons/util/CarriedExecutor.kt @@ -21,7 +21,7 @@ import java.util.concurrent.locks.LockSupport */ class CarriedExecutor(private val parentExecutor: Executor) : Runnable, ExecutorService { private val isCarried = AtomicBoolean() - private val queue = ConcurrentLinkedQueue() + private val queue = ConcurrentLinkedQueue>() private val isShutdown = AtomicBoolean() private val isTerminated = AtomicBoolean() @@ -29,7 +29,7 @@ class CarriedExecutor(private val parentExecutor: Executor) : Runnable, Executor if (isShutdown.get()) throw RejectedExecutionException("Shutdown initiated") - queue.add(command) + queue.add(FutureTask(command, Unit)) if (!isShutdown.get() && isCarried.compareAndSet(false, true)) parentExecutor.execute(this) @@ -51,6 +51,7 @@ class CarriedExecutor(private val parentExecutor: Executor) : Runnable, Executor var next = queue.poll() while (next != null) { + next.cancel(false) tasks.add(next) next = queue.poll() } @@ -141,23 +142,10 @@ class CarriedExecutor(private val parentExecutor: Executor) : Runnable, Executor } override fun run() { - if (isShutdown.get()) { - shutdownNow() - isCarried.set(false) - return - } - var next = queue.poll() while (next != null) { next.run() - - if (isShutdown.get()) { - shutdownNow() - isCarried.set(false) - return - } - next = queue.poll() }