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