Skip to content

Commit

Permalink
启动优化
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchong211 committed Mar 31, 2022
1 parent cea1077 commit 641fdfa
Show file tree
Hide file tree
Showing 13 changed files with 537 additions and 323 deletions.
4 changes: 3 additions & 1 deletion Business/DemoBusiness/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ dependencies {
implementation project(path: ':CountTimerLib')
implementation(rootProject.ext.dependencies["okhttp"])
implementation(rootProject.ext.dependencies["gson"])
implementation project(path: ':RouteManager')
implementation project(path: ':YCDialogLib')

implementation project(path: ':RouteManager')
implementation project(path: ':RouteAnnotations')
annotationProcessor project(path: ':RouteCompiler')

implementation 'com.github.yangchong211.YCAppTool:ServiceLoaderApi:1.4.2.4'
Expand Down
28 changes: 0 additions & 28 deletions Business/GameBusiness/src/main/java/com/yc/book/BookApp.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class AppTaskDispatcher {
public final class AppTaskDispatcher {
//所有任务需要等待的时间
private static final int WAITING_TIME = 10000;
//存放每个Task (key= Class < ? extends AppStartTask>)
Expand Down Expand Up @@ -112,7 +112,9 @@ private void printSortTask() {
private void dispatchAppStartTask() {
//再发送非主线程的任务
for (AppStartTask appStartTask : mSortThreadPoolTaskList) {
appStartTask.runOnExecutor().execute(new AppTaskRunnable(appStartTask, this));
AppTaskRunnable runnable = new AppTaskRunnable(appStartTask, this);
//提交一个事务
appStartTask.runOnExecutor().execute(runnable);
}
//再发送主线程的任务,防止主线程任务阻塞,导致子线程任务不能立刻执行
for (AppStartTask appStartTask : mSortMainThreadTaskList) {
Expand All @@ -121,7 +123,7 @@ private void dispatchAppStartTask() {
}

//通知Children一个前置任务已完成
public void setNotifyChildren(AppStartTask appStartTask) {
void setNotifyChildren(AppStartTask appStartTask) {
List<Class<? extends AppStartTask>> arrayList = mTaskChildHashMap.get(appStartTask.getClass());
if (arrayList != null && arrayList.size() > 0) {
for (Class<? extends AppStartTask> aclass : arrayList) {
Expand All @@ -134,7 +136,7 @@ public void setNotifyChildren(AppStartTask appStartTask) {
}

//标记已经完成的Task
public void markAppStartTaskFinish(AppStartTask appStartTask) {
void markAppStartTaskFinish(AppStartTask appStartTask) {
AppTaskUtils.showLog(isShowLog, "任务完成了:" + appStartTask.getClass().getSimpleName());
if (ifNeedWait(appStartTask)) {
mCountDownLatch.countDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public AppTaskRunnable(AppStartTask appStartTask, AppTaskDispatcher appStartTask

@Override
public void run() {
Process.setThreadPriority(appStartTask.priority());
int priority = appStartTask.priority();
Process.setThreadPriority(priority);
appStartTask.waitToNotify();
appStartTask.run();
appStartTaskDispatcher.setNotifyChildren(appStartTask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


public interface TaskInterface {

//线程的优先级
@IntRange(from = Process.THREAD_PRIORITY_FOREGROUND, to = Process.THREAD_PRIORITY_LOWEST)
int priority();
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


<application
android:name="com.yc.lifehelper.MainApplication"
android:name="com.yc.lifehelper.application.MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_yc_name"
Expand Down
288 changes: 0 additions & 288 deletions app/src/main/java/com/yc/lifehelper/MainApplication.java

This file was deleted.

Loading

0 comments on commit 641fdfa

Please sign in to comment.