本文介绍了超过线程池9和排队的任务128时android应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序传导api每隔10秒从网络提供商的gps位置调用一次.用户也可以执行几个api调用.

The application conduction api calls in every 10seconds with the gps location from the network provider. And also there are several api calls can be do by the user.

应用程序因法律互联网或互联网连接减少而崩溃(设备数据访问权限)有没有适当的方法来防止应用程序崩溃并保持api请求,直到互联网可用.

application is crashing with law internet or less internet connection(device data access)is there a proper way to prevent app crashing and hold the api request till the internet network available.

我在这里发布我的崩溃提示堆栈跟踪

here im posting my crash reprort stacktrace

java.util.concurrent.RejectedExecutionException: 
Task android.os.AsyncTask$3@4206a5b0 rejected from java.util.concurrent.ThreadPoolExecutor@41e97858[Running, pool size = 9, active threads = 9, queued tasks = 128, completed tasks = 2]    
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2011)  
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:793)  
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1339)    
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:590)   
at com.pickme.driver.service.LocationUpdate$LocationUpdateTask$1.run(LocationUpdate.java:216)   
at android.os.Handler.handleCallback(Handler.java:733)  
at android.os.Handler.dispatchMessage(Handler.java:95)  
at android.os.Looper.loop(Looper.java:136)  
at android.app.ActivityThread.main(ActivityThread.java:5333)    
at java.lang.reflect.Method.invokeNative(Native Method)     
at java.lang.reflect.Method.invoke(Method.java:515)     
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:895)  
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:711)     
at dalvik.system.NativeStart.main(Native Method)

推荐答案

queued tasks = 128表示您已达到AsyncTask的最大任务数:

queued tasks = 128 indicates that you have reached maximum count of tasks for AsyncTask:

私有静态final BlockingQueue sPoolWorkQueue = 新的LinkedBlockingQueue(128);

private static final BlockingQueue sPoolWorkQueue = new LinkedBlockingQueue(128);

一种方法是将作业以某种数据结构(例如捆绑包)排队,然后将其存储在某些数据库(sqlite)中.无论如何这将是有用的,因为如果用户将终止您的应用程序,那么现在您所有的任务都将丢失.如果它们保留在sqlite中-那么您可以在下次应用运行时将其发送.

one aproach is to queue your jobs in some data structure, in example bundles and store it in some database (sqlite). It would be usefull anyway because if user will terminate your application, then now all your tasks are lost. If they are persisted in sqlite - then you can send them on next app run.

您还可以使用 Executors.newSingleThreadExecutor ,它具有无限制的队列,但是您必须自己进行任何UI更新-例如使用处理程序. AsyncTask的实现基于执行器.

You could also use Executors.newSingleThreadExecutor, which has unbounded queue, but you would have to do any UI updates yourself - in example with handlers. AsyncTask-s implementation is based on Executors.

这篇关于超过线程池9和排队的任务128时android应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 15:07