Java: Multithreading & UDP Socket Programming

后端 未结 4 919
闹比i
闹比i 2021-02-10 18:42

I am new to multithreading & socket programming in Java. I would like to know what is the best way to implement 2 threads - one for receiving a socket and one for sending a

4条回答
  •  难免孤独
    2021-02-10 19:10

    2 threads is fine. One reader another writer. Remember that with UDP you should not spawn new handler threads (unless what you're doing takes a long time), I recommend throwing the incoming messages into a processing Queue. The same for the send, have a send thread that blocks on an incoming Queue for UDP send.

提交回复
热议问题