generated from mingliqiye/lib-tem
- 将多个Java文件转换为Kotlin文件,包括CallType、QuickBaseTypeHandler等 - 升级Netty版本从4.2.9.Final到4.130.Final - 添加新的Netty重连调度器ClientScheduleReconnect功能 - 新增DateTime和MySQL UUID类型处理器支持 - 创建命名线程工厂NamedThreadFactory用于线程池管理 - 修复UUID转换方法名称错误 - 更新项目版本号从4.2.7到4.3.2 - 移除Java版本的ValueGetter类,使用Kotlin数据类替代
74 lines
2.3 KiB
Kotlin
74 lines
2.3 KiB
Kotlin
/*
|
|
* Copyright 2026 mingliqiye
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* ProjectName mingli-utils
|
|
* ModuleName mingli-utils.main
|
|
* CurrentFile NamedThreadFactory.kt
|
|
* LastUpdate 2026-01-08 13:21:00
|
|
* UpdateUser MingLiPro
|
|
*/
|
|
|
|
package com.mingliqiye.utils.netty
|
|
|
|
import io.netty.util.concurrent.FastThreadLocalThread
|
|
import java.util.concurrent.ThreadFactory
|
|
import java.util.concurrent.atomic.AtomicInteger
|
|
|
|
|
|
open class NamedThreadFactory(private val getName: NamedThreadFactoryNameGetter) : ThreadFactory {
|
|
|
|
companion object {
|
|
|
|
@JvmStatic
|
|
private val allThreadPoolNumber = AtomicInteger(0)
|
|
|
|
@FunctionalInterface
|
|
fun interface NamedThreadFactoryNameGetter {
|
|
fun getName(clazz: Class<out NamedThreadFactory>, poolNumber: Int, threadNumber: Int): String
|
|
}
|
|
|
|
@JvmStatic
|
|
val defaultGetName =
|
|
NamedThreadFactoryNameGetter { clazz, poolNumber, threadNumber -> "${clazz.simpleName}-$poolNumber-$threadNumber" }
|
|
|
|
@JvmStatic
|
|
fun of(name: String): NamedThreadFactory {
|
|
return NamedThreadFactory { a, b, c ->
|
|
"$name-$c"
|
|
}
|
|
}
|
|
|
|
@JvmStatic
|
|
fun of(getter: NamedThreadFactoryNameGetter = defaultGetName): NamedThreadFactory {
|
|
return NamedThreadFactory(getter)
|
|
}
|
|
}
|
|
|
|
|
|
private val threadNumber = AtomicInteger(0)
|
|
private val threadPoolNumber = allThreadPoolNumber.addAndGet(1)
|
|
|
|
open fun getThreadName(clazz: Class<out NamedThreadFactory>, poolNumber: Int, threadNumber: Int) =
|
|
getName.getName(clazz, poolNumber, threadNumber)
|
|
|
|
override fun newThread(r: Runnable): Thread {
|
|
return FastThreadLocalThread(
|
|
null,
|
|
r,
|
|
getThreadName(this.javaClass, threadPoolNumber, threadNumber.addAndGet(1))
|
|
)
|
|
}
|
|
}
|