Go channel vs Java BlockingQueue

后端 未结 4 680
日久生厌
日久生厌 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-01 23:58

    To do something similar to golang'select statement in java would involve using the java.nio package. Specifically selectors and channels. Check out the package docs here:

    http://docs.oracle.com/javase/6/docs/api/java/nio/channels/package-summary.html#multiplex

    It offers pretty much the same capability as the golang select statement, using a single thread to multiplex reading/writing from multiple channels.

提交回复
热议问题