didi / booster

🚀Optimizer for mobile applications
https://booster.johnsonlee.io
Apache License 2.0
4.89k stars 580 forks source link

线程优化插件,会在android5.1及以下版本报错。 #357

Closed CodeIdeal closed 2 years ago

CodeIdeal commented 2 years ago

reproduce repo: https://github.com/CodeIdeal/booster_adnroid_5_incompatible_example

大致看了下,好像是因为在android5.1以下时,默认的keepAliveTime为0. 在低版本中使用线程优化插件回因为主动调用allowCoreThreadTimeOut,从而导致在校验keepAliveTime值的时候抛出IllegalArgumentException。

    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();
        }
    }

这个问题应该可以在ShadowScheduledThreadPoolExecutor中直接指定默认的keepAliveTime值解决。

CodeIdeal commented 2 years ago

359 目前已提了PR,如果没问题麻烦合并下。 @johnsonlee