E
E
Ernest Farukshin2019-12-08 01:36:53
Java
Ernest Farukshin, 2019-12-08 01:36:53

What is better to use multithreading or non-blocking input / output for the messenger?

What is better to use multithreading or NIO for a messenger.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2019-12-08
@Ernest3

It is better to use the technology that is more suitable for solving specific problems in certain conditions. They are not mentioned in your question.

V
Vladimir Korotenko, 2019-12-08
@firedragon

It is wasteful to create a thread for each request, use asynchrony.
The architecture is something like this:
1. define bindings to ip
2. in a loop create a listener for each ip (or bind to 0.0.0.0)
3. create an array of input buffers for each listener
4. add the connection to the buffer when connecting
5. read data and what then do with them
Look at this example, there are wrappers in Jave, but the essence is the same
https://www.ibm.com/support/knowledgecenter/ssw_ib...

X
xmoonlight, 2019-12-08
@xmoonlight

Multithreading is not about connections, but threads processing each connection.
NIO is network communication.
You have to use both!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question