Is the Java multicastsocket thread safe?

I have two themes

It seems to work normally, but I still doubt it

Can these two threads use the same multicast socket instance? Is the multicastsocket thread safe in sending / receiving method calls?

Solution

The send and receive datagram socket methods are synchronized on the send / receive datagram packet In other words, if you use the same datagram packet to send and receive from two different threads, the two methods will be synchronized because they will use the same object as the synchronization token

Once you look at the source code of datagram socket, it will be easier to understand

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>