1

I have 2 threads that want to invoke:

multicastSocket.send(dP1) and

multicastSocket.send(dP2)

respectively, where dP1 and dP2 are different DatagramPacket objects, and multicastSocket is the shared instance of MulticastSocket.

I don't understand if concurrency problems may happen on multicastSocket, if the threads call send() in the same moment.

Andrew Spencer
  • 15,164
  • 4
  • 29
  • 48
diningphil
  • 416
  • 5
  • 18
  • possible duplicate http://stackoverflow.com/questions/3108644/is-java-multicastsocket-threadsafe – Alex May 30 '15 at 16:00
  • Alex, looking at the bottom of the question you linked, it is said that send is not a synchronized method. So concurrency problems may eventually happen? However I guess this is not a duplicate question. – diningphil May 30 '15 at 16:06
  • edit: title now says what the question is really asking – Andrew Spencer Jun 02 '15 at 12:29

1 Answers1

2
  • DatagramSocket reads and writes are independent of each other.
  • DatagramSocket writes are atomic so they are thread-safe.
  • DatagramSocket reads are synchronized by Java and they are also atomic at the OS level so again they are thread-safe.
  • MulticastSocket inherits these methods from DatagramSocket so the same applies to it.
user207421
  • 305,947
  • 44
  • 307
  • 483