FATAL EXCEPTION: main
Process: tech.cabana.toys, PID: 11857
java.lang.RuntimeException: Unable to start activity ComponentInfo{tech.cabana.toys/tech.cabana.toys.MainActivity}: java.lang.IllegalArgumentException: Core threads must have nonzero keep alive times
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2587)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2659)
at android.app.ActivityThread.access$1000(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1467)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:159)
at android.app.ActivityThread.main(ActivityThread.java:5671)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
Caused by: java.lang.IllegalArgumentException: Core threads must have nonzero keep alive times
at java.util.concurrent.ThreadPoolExecutor.allowCoreThreadTimeOut(ThreadPoolExecutor.java:1639)
at com.didiglobal.booster.instrument.ShadowScheduledThreadPoolExecutor.<init>(ShadowScheduledThreadPoolExecutor.java:43)
at tech.cabana.toys.MainActivity.onCreate(MainActivity.kt:16)
at android.app.Activity.performCreate(Activity.java:6162)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2508)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2659)
at android.app.ActivityThread.access$1000(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1467)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:159)
at android.app.ActivityThread.main(ActivityThread.java:5671)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
public void allowCoreThreadTimeOut(boolean value) {
if (value && keepAliveTime <= 0)
throw new IllegalArgumentException("Core threads must have nonzero keep alive times");
if (value != allowCoreThreadTimeOut) {
allowCoreThreadTimeOut = value;
if (value)
interruptIdleWorkers();
}
}
reproduce repo: https://github.com/CodeIdeal/booster_adnroid_5_incompatible_example
大致看了下,好像是因为在android5.1以下时,默认的keepAliveTime为0. 在低版本中使用线程优化插件回因为主动调用allowCoreThreadTimeOut,从而导致在校验keepAliveTime值的时候抛出IllegalArgumentException。
这个问题应该可以在ShadowScheduledThreadPoolExecutor中直接指定默认的keepAliveTime值解决。