Android WorkManager 10 minute thread timeout coming from somewhere

梦想的初衷 提交于 2019-12-23 18:36:56

问题


I'm using android.arch.work:work-runtime:1.0.0-alpha12 to run one and only one long-running task. The process can take as much as 20 minutes on an old (slow) device. This is the code snippet used to start the task:

        OneTimeWorkRequest databaseWork =
            new OneTimeWorkRequest.Builder(DatabaseWorker.class)
                    .build();
        WorkManager.getInstance().enqueue(databaseWork);

For background info, databaseWork is retrieving an encrypted zip file, decrypting it, then using the contents to restore a bunch of tables in a SqlCipher db. If the database is large this can take a while

In one instance the task is running on Thread [pool-1-thread-1,5,main], and as near as I can tell at exactly 10 minutes (600 seconds) of elapsed time, Thread [pool-2-thread-1,5,main] creates a CancellationException with a null cause. If I use the debugger to stop this thread from completing with its exception, then the first thread runs just fine to completion. If I let the second thread fail with its CancellationException, it then tries to enqueue the long-running task again, so I have to defend against a second run while the first thread is still processing.

Does anyone know if a Worker, or the ThreadPoolExecutor it uses, or some other involved class has this 10 minute thread processing limit, and if so is there a way to change it? I've been looking at doc and setting breakpoints in the AbstractFuture class that creates the CancellationException, as well as the ThreadPoolExecutor used and can't see where this timeout is being set or used. Still looking though :-)

I've looked briefly at the open issues for WorkManager and don't see this timeout mentioned. Also haven't seen reference to a timeout like this in any of the WorkManager doc. If anyone can point me at a solution or info about this, thanks in advance!


回答1:


Does anyone know if a Worker, or the ThreadPoolExecutor it uses, or some other involved class has this 10 minute thread processing limit

JobScheduler does, and WorkManager delegates to JobScheduler on Android 5.0+ devices.

and if so is there a way to change it?

Not directly.

If you break your work up into smaller chunks and chain them using WorkManager, you might be able to get all the work done, albeit possibly with delays between the chunks.



来源:https://stackoverflow.com/questions/53734165/android-workmanager-10-minute-thread-timeout-coming-from-somewhere

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!