Some semantic fixes to carriedexecutor
This commit is contained in:
parent
021b991ab5
commit
b76c4e6aa9
@ -4,7 +4,7 @@ kotlin.code.style=official
|
|||||||
specifyKotlinAsDependency=false
|
specifyKotlinAsDependency=false
|
||||||
|
|
||||||
projectGroup=ru.dbotthepony.kommons
|
projectGroup=ru.dbotthepony.kommons
|
||||||
projectVersion=2.2.0
|
projectVersion=2.2.1
|
||||||
|
|
||||||
guavaDepVersion=33.0.0
|
guavaDepVersion=33.0.0
|
||||||
gsonDepVersion=2.8.9
|
gsonDepVersion=2.8.9
|
||||||
|
@ -21,7 +21,7 @@ import java.util.concurrent.locks.LockSupport
|
|||||||
*/
|
*/
|
||||||
class CarriedExecutor(private val parentExecutor: Executor) : Runnable, ExecutorService {
|
class CarriedExecutor(private val parentExecutor: Executor) : Runnable, ExecutorService {
|
||||||
private val isCarried = AtomicBoolean()
|
private val isCarried = AtomicBoolean()
|
||||||
private val queue = ConcurrentLinkedQueue<Runnable>()
|
private val queue = ConcurrentLinkedQueue<FutureTask<*>>()
|
||||||
private val isShutdown = AtomicBoolean()
|
private val isShutdown = AtomicBoolean()
|
||||||
private val isTerminated = AtomicBoolean()
|
private val isTerminated = AtomicBoolean()
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ class CarriedExecutor(private val parentExecutor: Executor) : Runnable, Executor
|
|||||||
if (isShutdown.get())
|
if (isShutdown.get())
|
||||||
throw RejectedExecutionException("Shutdown initiated")
|
throw RejectedExecutionException("Shutdown initiated")
|
||||||
|
|
||||||
queue.add(command)
|
queue.add(FutureTask(command, Unit))
|
||||||
|
|
||||||
if (!isShutdown.get() && isCarried.compareAndSet(false, true))
|
if (!isShutdown.get() && isCarried.compareAndSet(false, true))
|
||||||
parentExecutor.execute(this)
|
parentExecutor.execute(this)
|
||||||
@ -51,6 +51,7 @@ class CarriedExecutor(private val parentExecutor: Executor) : Runnable, Executor
|
|||||||
var next = queue.poll()
|
var next = queue.poll()
|
||||||
|
|
||||||
while (next != null) {
|
while (next != null) {
|
||||||
|
next.cancel(false)
|
||||||
tasks.add(next)
|
tasks.add(next)
|
||||||
next = queue.poll()
|
next = queue.poll()
|
||||||
}
|
}
|
||||||
@ -141,23 +142,10 @@ class CarriedExecutor(private val parentExecutor: Executor) : Runnable, Executor
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (isShutdown.get()) {
|
|
||||||
shutdownNow()
|
|
||||||
isCarried.set(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var next = queue.poll()
|
var next = queue.poll()
|
||||||
|
|
||||||
while (next != null) {
|
while (next != null) {
|
||||||
next.run()
|
next.run()
|
||||||
|
|
||||||
if (isShutdown.get()) {
|
|
||||||
shutdownNow()
|
|
||||||
isCarried.set(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
next = queue.poll()
|
next = queue.poll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user