在阅读有关 java 的并发 api 时,我开始了解Exchanger
类。
从 Java 文档,
"A synchronization point at which threads can pair and swap elements within pairs. Each thread presents some object on entry to the exchange method, matches with a partner thread, and receives its partner's object on return. An Exchanger may be viewed as a bidirectional form of a SynchronousQueue. Exchangers may be useful in
applications such as genetic algorithms and pipeline designs.
"
我探索并找到了以下链接The Exchanger & GC-less Java
它说 ,
“Exchanger 类对于在两个线程之间来回传递数据很有用。例如生产者/消费者。它具有自然回收用于传递工作的数据结构的特性,并以有效的方式支持无 GC 的工作共享。”
它如何支持"GC-less sharing of work"
?