0

in what cases do I need to use treads when writing a UDP server in java and in what other cases it's not necessary ?

2 Answers 2

1

You need threads when the requests are non-trivial.

For example, an echo or date or message-of-the-day server can produce the response practically instantaneously, so it doesn't need threads.

A DNS server on the other hand may have to delegate the request, and can't keep other clients waiting while it does so, so it would need threads, or select(), or async I/O.

Sign up to request clarification or add additional context in comments.

2 Comments

is it necessary for Broadcasting to Multiple Recipients ? as in docs.oracle.com/javase/tutorial/networking/datagrams/…
It has nothing to do with broadcasting, or sending in general. It is about how you process an inbound request.
0

You'll need threads if you want to process multiple client requests at the same time i.e. high throughput. Let's say for each incoming UDP request, you need to access the database and send a signal to another service. This processing can take a long time and can block new requests, affecting performance, if you are doing it all in the same thread. With a multithreaded approach, each incoming DatagramPacket will be given to a thread as soon it is received which does the processing in parallel with other requests.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.