In my application I am using Async tasks in many places, recently I am facing problem where doInBackground of the below Async task is not getting called, this is happening when I execute the below Async task for the 3rd time (other Async tasks are also running).
protected class StatusTask extends AsyncTask<Void, Void, Void> {
private final BluetoothDevice device;
public StatusTask(BluetoothDevice device) {
this.device = device;
}
@Override
protected Void doInBackground(Void... voids) {
while (true) {
if (someCondition) {
Log.D(TAG,"hi hello")
break;
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
//e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
tTask=null;
}
@Override
protected void onCancelled() {
super.onCancelled();
System.out.println("onCancelled " + this.isCancelled());
}
@Override
protected void onCancelled(Void aVoid) {
super.onCancelled(aVoid);
System.out.println("onCancelled result " + this.isCancelled());
}
}
i am executing above task as,
StatusTask tTask = new StatusTask(device);
tTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
I am running on Android version 4.4.3.
How do I find out how many Sync tasks are running currently in my app? Bcz I guess CORE_POOL_SIZE count might be causing the problem.
Or if deadlock or any other situation is happened and blocking new Async task to get executed, is there a way in android studio to identity and kill the other Async tasks which may not be useful?
If I use CustomThreadPoolExecutor as disconnectTask.executeOnExecutor(mCustomThreadPoolExecutor); with more CorePoolSize its working fine but doInBackground() of next Async task which is using AsyncTask.THREAD_POOL_EXECUTOR is not getting called.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…