|
|
@@ -16,12 +16,17 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
*/
|
|
|
public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
|
|
|
|
|
+ // 动态获取系统CPU核心数
|
|
|
+ private static final int CPU_CORES = Runtime.getRuntime().availableProcessors();
|
|
|
+ // 计算线程数,确保至少为1(处理CPU核心数为1的边界情况)
|
|
|
+ private static final int THREAD_COUNT = Math.max(1, CPU_CORES / 2);
|
|
|
+
|
|
|
// 线程池用于异步处理视频转码
|
|
|
private static final ExecutorService TRANSCODE_EXECUTOR = new ThreadPoolExecutor(
|
|
|
- 1, // 核心线程数,根据服务器CPU核心数调整
|
|
|
- Runtime.getRuntime().availableProcessors() / 2, // 最大线程数,使用一半的CPU核心
|
|
|
+ THREAD_COUNT, // 核心线程数,系统CPU核心数的一半
|
|
|
+ THREAD_COUNT, // 最大线程数,系统CPU核心数的一半
|
|
|
60L, TimeUnit.SECONDS,
|
|
|
- new LinkedBlockingQueue<>(10), // 任务队列,限制等待任务数
|
|
|
+ new LinkedBlockingQueue<>(20), // 任务队列,限制等待任务数
|
|
|
new ThreadFactory() {
|
|
|
private final AtomicInteger counter = new AtomicInteger(0);
|
|
|
@Override
|
|
|
@@ -166,4 +171,4 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
|
|
return config.getBasePath() + File.separator + path;
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+}
|