Is Java MulticastSocket threadsafe?

萝らか妹 提交于 2019-11-29 07:13:22
Boris Pavlović

Both send and receive DatagramSocket methods are synchronized on the sending/receiving datagram packet. In other words if you are using a same datagram packet to send and receive from two different threads these two methods will be synchronized as they are going to use the same object as a synchronization token.

It's much easier to understand once looked at the source code of DatagramSocket.

DatagramSocket is thread safe, MulticastSocket is a derivative class, in consequence MulticastSocket.send is thread-safe, since access is being serialized by a synchronized block.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!