Android WorkManager 10分钟线程超时来自某处 [英] Android WorkManager 10 minute thread timeout coming from somewhere

查看:111
本文介绍了Android WorkManager 10分钟线程超时来自某处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用android.arch.work:work-runtime:1.0.0-alpha12运行一个并且只有一个长时间运行的任务.在旧的(慢速)设备上,此过程最多可能需要20分钟.这是用于启动任务的代码片段:

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

有关背景信息,databaseWork正在检索一个加密的zip文件,将其解密,然后使用其内容在SqlCipher db中还原一堆表.如果数据库很大,则可能需要一段时间

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

在一个实例中,任务正在线程[pool-1-thread-1,5,main]上运行,而我所知道的恰好在经过10分钟(600秒)的时间里就是线程[pool-2-thread-1,5,main]创建一个具有空原因的CancellationException.如果我使用调试器阻止该线程异常结束,则第一个线程可以正常运行.如果我让第二个线程由于其CancellationException而失败,那么它将尝试再次使长时间运行的任务入队,因此我必须在第一个线程仍在处理时防止第二次运行.

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.

有人知道工人,它使用的ThreadPoolExecutor或其他涉及的类是否具有10分钟的线程处理限制,如果有,可以更改它吗?我一直在研究文档和在创建CancellationException的AbstractFuture类中设置断点,以及所使用的ThreadPoolExecutor,无法看到在哪里设置或使用了此超时.仍在寻找:-)

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 :-)

我已经简要查看了WorkManager的未解决问题,但没有看到此超时.还没有在任何WorkManager文档中看到对此类超时的引用.如果有人可以给我指出解决方案或有关此的信息,请提前致谢!

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!

推荐答案

有人知道工人,工人使用的ThreadPoolExecutor或其他涉及的类是否具有10分钟的线程处理限制

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

JobScheduler 会执行,并且 WorkManager 会委派给Android 5.0+设备上的 JobScheduler .

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

是否可以更改它?

and if so is there a way to change it?

不直接.

如果您将工作分解为较小的块,并使用 WorkManager 将它们链接起来,则尽管这些块之间可能会有延迟,但您也许能够完成所有工作.

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.

这篇关于Android WorkManager 10分钟线程超时来自某处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆