mirror of
https://github.com/geekwenjie/SmartJavaAI.git
synced 2026-09-11 04:08:55 +00:00
1、【核心升级】升级DJL版本到0.34.0
2、【平台支持】新增对 Linux ARM64 架构的全面支持 3、【通用视觉】集成零样本目标检测模型 4、【活体检测】优化视频检测流程,实现 Predictor 视频会话级复用 5、【人脸识别】SQLite人脸查询改进线程池 6、【人脸识别】修复 Milvus 向量库下 listFaces 接口的调用异常
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cn.smartjavaai</groupId>
|
||||
<artifactId>smartjavaai-parent</artifactId>
|
||||
<version>1.0.27</version>
|
||||
<version>1.1.0</version>
|
||||
</parent>
|
||||
|
||||
<name>common</name>
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package cn.smartjavaai.common.executor;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author dwj
|
||||
* @date 2025/11/26
|
||||
*/
|
||||
public class GlobalExecutor {
|
||||
|
||||
private static volatile ExecutorService executor;
|
||||
|
||||
public static ExecutorService getExecutor() {
|
||||
if (executor == null) {
|
||||
synchronized (GlobalExecutor.class) {
|
||||
if (executor == null) {
|
||||
int cores = Runtime.getRuntime().availableProcessors();
|
||||
executor = new ThreadPoolExecutor(
|
||||
cores,
|
||||
cores * 2,
|
||||
60L, TimeUnit.SECONDS,
|
||||
new SynchronousQueue<>(),
|
||||
runnable -> {
|
||||
Thread t = new Thread(runnable);
|
||||
t.setDaemon(true); // 守护线程
|
||||
return t;
|
||||
},
|
||||
new ThreadPoolExecutor.DiscardOldestPolicy()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return executor;
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
if (executor != null) {
|
||||
executor.shutdown();
|
||||
try {
|
||||
if (!executor.awaitTermination(5, TimeUnit.SECONDS)) {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
executor.shutdownNow();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user