I have a college project where I need to use threads to run tasks in paralel. I started using AsyncTask and the simple task.execute(params), but then I found out that this does not allow multiple Asynctasks to run, just one per time. Then I discovered task.executeOnExecutor, which I use like this(code inside my ElevatorControl class):
taskDesligaLampada.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "");
I execute this in my ElevatorControl class(which is not an activity). The funny thing is: executeOnExecutor is not starting the doInBackground method of the task. I tried using Logging for debuggig like this(inside my AsyncTask):
@Override
protected String doInBackground(String... string_qualquer)
{
//PAREI AKI PARECE QUE ESSA TASK NÃO EXECUTA. PROBLEMA DO EXECUTE ON EXECUTOR?
Log.i("ElevatorControl", "Elevador id=" + elevatorControl.getIdElevador() + ";fechando porta");
this.interfaceDaPorta.fecharPorta(andarAtual, this.elevatorControl.getIdElevador());
return "";
}
but the log does not appear on logCat, which means it's not running. Tried catching the State variable returned after executteOnExecutor like this(method inside my ElevatorControl task):
//os eventos abaixo deveriam ser concorrentes. Por isso as tasks foram criadas
TaskFechaPorta taskFechaPorta = new TaskFechaPorta(this, interfaceDaPorta, sobeOuDesceOuParado, andarAtual);
Status statusThreadRoda = taskFechaPorta.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, "").getStatus();
and, by debugging, I found out that this Status is "running". The why is it not running the doInBackground method of my task?
can anyone say me what am I doing wrong?
P.S.: I use a LOT of asyncTasks for my project, at least 18 running because my teacher said so.