mirror of
https://github.com/tursom/TursomServer.git
synced 2025-02-08 18:50:11 +08:00
update ShutdownHook
This commit is contained in:
parent
228a1137b7
commit
21ad18eecb
@ -1,7 +1,6 @@
|
||||
package cn.tursom.core
|
||||
|
||||
import com.sun.org.slf4j.internal.LoggerFactory
|
||||
import java.lang.ref.Reference
|
||||
import java.lang.ref.SoftReference
|
||||
import java.util.concurrent.ConcurrentLinkedDeque
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
@ -14,10 +13,6 @@ import java.util.concurrent.atomic.AtomicInteger
|
||||
object ShutdownHook {
|
||||
private val logger = LoggerFactory.getLogger(ShutdownHook::class.java)
|
||||
|
||||
private val shutdownHooks = ConcurrentLinkedDeque<Reference<(() -> Unit)?>>()
|
||||
private val availableThreadCount = Runtime.getRuntime().availableProcessors() * 2
|
||||
private val activeThreadCount = AtomicInteger()
|
||||
|
||||
interface Reference<out T> {
|
||||
fun get(): T
|
||||
}
|
||||
@ -31,6 +26,10 @@ object ShutdownHook {
|
||||
}
|
||||
}
|
||||
|
||||
private val shutdownHooks = ConcurrentLinkedDeque<Reference<(() -> Unit)?>>()
|
||||
private val availableThreadCount = Runtime.getRuntime().availableProcessors() * 2
|
||||
private val activeThreadCount = AtomicInteger()
|
||||
|
||||
fun addHook(softReference: Boolean = false, hook: () -> Unit): Hook {
|
||||
if (activeThreadCount.incrementAndGet() <= availableThreadCount) {
|
||||
addWorkThread()
|
||||
|
Loading…
Reference in New Issue
Block a user