英文:
How can I give the notification to another thread while both are in infinite loop
问题
我的循环线程正在更新ArrayList中的数据。在ArrayList完成后,我需要向其他线程发送通知,以便其他线程可以将其插入到DB表中。但在记录到DB表时,我的其他线程应该等待。
英文:
My cyclic thread is updating the data in arraylist. After completion of arraylist I need to send notification to other thread so that other thread can insert it into dbtables. But during logging to dbtables my other thread should wait.
答案1
得分: 0
Semaphore是一个不错的起点。你可以使用这个链接作为参考:http://tutorials.jenkov.com/java-concurrency/semaphores.html#as-signal。
英文:
There are quite a few ways to do it. Semaphore would be a good starting point. You can use this link as reference: http://tutorials.jenkov.com/java-concurrency/semaphores.html#as-signal.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论