Commit 6257d72d by pye52

增加Worker线程池的自定义配置项,避免开启过多的无用线程

parent 25997146
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.bgycc.smartcanteen">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
......@@ -23,7 +24,8 @@
android:theme="@style/AppTheme">
<activity android:name=".activity.MainActivity"
android:launchMode="singleInstance"
android:screenOrientation="landscape">
android:screenOrientation="landscape"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
......@@ -50,6 +52,11 @@
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<provider
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
tools:node="remove"
android:exported="false" />
</application>
</manifest>
\ No newline at end of file
......@@ -2,6 +2,10 @@ package com.bgycc.smartcanteen;
import android.app.Application;
import androidx.annotation.NonNull;
import androidx.work.Configuration;
import com.bgycc.smartcanteen.executor.SCTaskExecutor;
import com.blankj.utilcode.util.CrashUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.PathUtils;
......@@ -9,7 +13,7 @@ import com.blankj.utilcode.util.Utils;
import java.io.File;
public class RootApp extends Application {
public class RootApp extends Application implements Configuration.Provider {
private static final String LOG_PREFIX = "app";
private static final String LOG_DIR = "log";
......@@ -25,4 +29,12 @@ public class RootApp extends Application {
.setBorderSwitch(false)
.setFilePrefix(LOG_PREFIX);
}
@NonNull
@Override
public Configuration getWorkManagerConfiguration() {
return new Configuration.Builder()
.setExecutor(SCTaskExecutor.getIOThreadExecutor())
.build();
}
}
......@@ -22,7 +22,7 @@ public class DefaultTaskExecutor extends TaskExecutor {
private final Object mLock = new Object();
private final ScheduledExecutorService mThread = Executors.newScheduledThreadPool(6, new ThreadFactory() {
private static final String THREAD_NAME_STEM = "mqtt_thread_%d";
private static final String THREAD_NAME_STEM = "SmartCanteen_Thread_%d";
private final AtomicInteger mThreadId = new AtomicInteger(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment