The Android application fails when overtaking the Thread 9 pool and the pending tasks 128


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.

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

Task [email protected] rejected from [email protected][Running, pool size = 9, active threads = 9, queued tasks = 128, completed tasks = 2]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(
at java.util.concurrent.ThreadPoolExecutor.reject(
at java.util.concurrent.ThreadPoolExecutor.execute(
at android.os.AsyncTask.executeOnExecutor(
at com.pickme.driver.service.LocationUpdate$LocationUpdateTask$
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(
at dalvik.system.NativeStart.main(Native Method)

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

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

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.

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.