Real Life Examples For CountDownLatch and CyclicBarrier

前端 未结 11 1352
余生分开走
余生分开走 2021-01-30 13:52

One example is given by one of our trainers when he was explaining difference between CountDownLatch and CyclicBarrier.

CountDownLatch: Suppose a stone can be lifted by

11条回答
  •  天涯浪人
    2021-01-30 14:45

    A cyclic barrier as the name suggests can be used in cycles. For ex: I am a company hr looking for N number of resumes from various job portal feeds. I have a skillset array containing skills sorted in order of priority. For ex java,c#,python. I want to find N resumes matching java skillset, but if I dont find the required no. of resumes, I search again on the next skillset and so on.

    I create a worker each of which scans through the resumes, in the assigned job feeds. Both workers will start with the primary skillset search in their job feeds.

    After performing the search worker will check if the N resumes were found. If found, the worker will reset the barrier and return. Else it will wait for the other worker to complete. If still N resumes were not found, the search would be resumed again, on the next skill in the skillset array. So, search can be called recursively/cyclicly without needing to create a new cyclic barrier.

提交回复
热议问题