With GcmNetworkManager
, my understanding is two tasks with same tag can never run concurrently. This is according to documentation here
Per service, two tasks with the same tag will never execute concurrently. Should a newly-scheduled task arrive while an existing task is still running, the new task will be dropped. In addition, different tasks may be scheduled concurrently, each invoked in a separate thread, if their schedules overlap. It is up to you to ensure thread safety when scheduling multiple tasks.
My question is:
If we schedule a task (a OneoffTask
):
Task myTask = ... ;// create task of MY_TAG
gcmNetworkManager.schedule(myTask);
Then at some point later on we cancel it but let's assume it's currently running (its GcmTaskService:onRunTask
is still running on its thread):
// Cancel task
// At this point GcmTaskService:onServiceRun could still be running (on a different thread)!
// `GcmTaskService:onRunTask` will continue to run
gcmNetworkManager.cancelTask(MY_TAG, ..);
and then at another time later on, we re-schedule same tag:
// Re-schedule task.
// At this point GcmTaskService:onRunTask could still be running (on a different thread)!
Task myTask = ... ;// create task of MY_TAG
gcmNetworkManager.schedule(myTask);
when time comes to run GcmTaskService:onRunTask
for the re-scheduled task, does GcmNetworkManager
still knows there is a task running (GcmTaskService::onRunTask()
hasn't returned? (Note that at this point its tag was cancelled)
Or does it actually starts a new GcmTaskService
and callGcmTakService:onRunTask
because its tag was cancelled?
Which means there could actually be two GcmTaskService:onRunTask
running at same time for same tag.