diff --git a/app/src/main/java/com/fankes/apperrorstracking/utils/factory/ThreadPooFactory.kt b/app/src/main/java/com/fankes/apperrorstracking/utils/factory/ThreadPooFactory.kt new file mode 100644 index 0000000..33b4d30 --- /dev/null +++ b/app/src/main/java/com/fankes/apperrorstracking/utils/factory/ThreadPooFactory.kt @@ -0,0 +1,46 @@ +/* + * AppErrorsTracking - Added more features to app's crash dialog, fixed custom rom deleted dialog, the best experience to Android developer. + * Copyright (C) 2019-2022 Fankes Studio(qzmmcn@163.com) + * https://github.com/KitsunePie/AppErrorsTracking + * + * This software is non-free but opensource software: you can redistribute it + * and/or modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * and eula along with this software. If not, see + * + * + * This file is Created by fankes on 2022/10/3. + */ +package com.fankes.apperrorstracking.utils.factory + +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors + +/** + * 创建当前线程池服务 + * @return [ExecutorService] + */ +private val currentThreadPool get() = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()) + +/** + * 创建并启动新的临时线程池 + * + * 等待 [block] 执行完成并自动释放 + * @param block 方法块 + */ +fun newThread(block: () -> Unit) { + currentThreadPool.apply { + execute { + block() + shutdown() + } + } +} \ No newline at end of file