Go channel vs Java BlockingQueue

后端 未结 4 681
日久生厌
日久生厌 2021-02-01 23:55

Are there any differences between a Go channel and a Java BlockingQueue? Both are queues with similar blocking and memory model semantics. Optionally both can have a capacity se

4条回答
  •  孤街浪徒
    2021-02-02 00:20

    They can be used in similar ways.

    • Both can block on when putting/sending or taking/recieving.
    • Both have a capacity that governs when sending will block.

    The biggest differences are probably that go channels are considerably cheaper than a java object. and that go channels can be restricted to only send or only receive which can ensure some additional type enforcement regarding who can send and who can receive from a channel.

提交回复
热议问题