如何在两个线程都处于无限循环中时向另一个线程发送通知?

huangapple go评论71阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年8月11日 07:26:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/63349401.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定