Java NIO Pipe vs BlockingQueue

后端 未结 4 2032
广开言路
广开言路 2021-02-04 12:04

I just discovered that just has an NIO facility, Java NIO Pipe that\'s designed for passing data between threads. Is there any advantage of using this mechanism over the more co

4条回答
  •  时光取名叫无心
    2021-02-04 12:18

    I suppose the pipe will have better latency as it could very likely be implemented with coroutines behind the scenes. Thus, the producer immediately yields to the consumer when data is available, not when the thread scheduler decides.

    Pipes in general represent a consumer-producer problem and are very likely to be implemented this way so that both threads cooperate and are not preempted externally.

提交回复
热议问题