0
對不起,傢伙沒有太多的代碼發佈。 我有以下程序結構。CountDownLatch是否可以在Android服務中使用?
MyService{
initialize CountDownLatch to 2
call InterntService1 - in the end of IntentService1 decrement the latch's counter
call IntentService2 -in the end of IntentService2 decrement the latch's counter
latch.await()
}
我現在面臨的問題是:一旦線程服務(如應用程序的主線程的一部分)開始等待,目的服務是根本不能執行。它只是在那裏等待無限。有沒有其他人面臨同樣的問題。我知道我可以使用處理程序/其他一些機制。但我的問題是,爲什麼會發生這種情況?
你爲什麼不能發佈更多的代碼? –
不要在主線程上使用'await'(因爲它是一種阻塞方法)。例如,如果您正在使用intentservice,則使用它非常合適。 – njzk2