Wait for multiple AsyncTask to complete

前端 未结 5 1026
自闭症患者
自闭症患者 2020-12-15 21:16

I am parallelizing my operation by splitting it in the exact number of cores available and then, by start the same number of AsyncTask, performing the same operation but on

5条回答
  •  借酒劲吻你
    2020-12-15 22:09

    You should use a CountDownLatch. Here the documentation with examples: java.util.concurrent.CountDownLatch

    Basically you give a reference of CountDownLatch to your threads, and each of them will decrement it when finished:

    countDownLatch.countDown();
    

    The main thread will wait on the termination of all threads using:

    countDownLatch.await();
    

提交回复
热议问题