[英]Wait for any task to finish, then start a new one
I'm wondering how could I, without doing my own implementation of reporting using blocking queues and similar, as easily as possible implement the following scenario: 我想知道如何在不使用阻塞队列等类似的情况下执行自己的报告实现,尽可能轻松地实现以下场景:
I have K * N tasks, every batch of N tasks is a bit different. 我有K * N任务,每批N个任务都有点不同。
The second point is repeated until all of the tasks are finished. 重复第二点,直到完成所有任务。
Should I use a CyclicBarrier and submit a task when there's one thread waiting? 当一个线程在等待时,我应该使用CyclicBarrier并提交任务吗? I guess I'd have to use a blocking queue to guarantee that I won't submit the same task twice.
我想我必须使用阻塞队列来保证我不会两次提交相同的任务。
如果要确保第一批不与第三批混合(等等),则可以为每批中使用批处理中的任务数初始化的CountDownLatch,并且批处理中的任务应等待()在对应于批次N-2的锁存器上,并且当任务完成时,它可以在其相应的锁存器上调用countDown()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.