[6.1.2][线程优化] 升级版本,更改初始化方式

This commit is contained in:
renwj
2023-10-27 18:00:29 +08:00
parent 08c22c5d9f
commit 41fe5887c1
11 changed files with 58 additions and 71 deletions

View File

@@ -75,6 +75,8 @@ dependencies {
implementation rootProject.ext.dependencies.koomjava
implementation rootProject.ext.dependencies.koomnative
implementation rootProject.ext.dependencies.koomxhook
implementation rootProject.ext.dependencies.thread_opt
api project(':test:crashreport-apmbyte')
compileOnly project(':core:function-impl:mogo-core-function-datacenter')
implementation project(':foudations:mogo-commons')

View File

@@ -5,7 +5,6 @@ import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_MAI
import android.content.Context;
import com.bytedance.boost_multidex.BoostMultiDex;
import com.mogo.cloud.socket.SocketBuildConfig;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.module.MogoModule;
@@ -15,14 +14,12 @@ import com.mogo.eagle.core.data.config.FunctionBuildConfig;
import com.mogo.eagle.core.data.constants.MogoServicePaths;
import com.mogo.eagle.core.function.api.chat.biz.ChatConsts;
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager;
import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager;
import com.mogo.eagle.core.function.call.startup.CallerStartUpManager;
import com.mogo.eagle.core.function.main.threadopt.ThreadOptInitializer;
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils;
import com.mogo.eagle.core.utilcode.mogo.AppLaunchTimeUtils;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import java.lang.reflect.Field;
/**
* 默认初始化一些基础服务配置
*/
@@ -80,6 +77,7 @@ public abstract class MainMoGoApplication extends AbsMogoApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
ThreadOptInitializer.init();
/*如果是主进程**/
// if (ProcessUtils.isMainProcess(this)) {
AppLaunchTimeUtils.beginTimeCalculate(AppLaunchTimeUtils.COLD_START);

View File

@@ -0,0 +1,47 @@
package com.mogo.eagle.core.function.main.threadopt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mogo.thread.opt.core.ThreadManager;
import com.mogo.thread.opt.core.annotation.Keep;
import com.mogo.thread.opt.core.config.ThreadConfig;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Keep
public class ThreadOptInitializer {
private static final ThreadConfig.TaskExecuteListener listener = new ThreadConfig.TaskExecuteListener() {
@Override
public boolean isEnabled() {
return true;
}
@Override
public void onExecutorBefore(@NonNull ThreadConfig.TaskType taskType, @Nullable Object task, @Nullable String desc) {
}
@Override
public void onExecutorAfter(@NonNull ThreadConfig.TaskType taskType, @Nullable Object task, @Nullable String desc) {
}
@Override
public void onExecutorStateChanged(@NonNull ThreadPoolExecutor threadPoolExecutor, int core, int max, int active, long completed) {
}
};
public static void init() {
ThreadConfig.Builder builder = new ThreadConfig.Builder();
builder.minKeepAliveTime(1, TimeUnit.SECONDS);
builder.maxKeepAliveTime(10, TimeUnit.SECONDS);
builder.listener(listener);
ThreadManager.INSTANCE.init(builder);
}
}