menu

arrow_back What is the best way to implement multithreading in a JAVA server program?

by
2 votes
Hello! I'm trying to write a server in Java. Server for mobile application, the server should take JSON request, search the database, generate and send JSON response. The essence of the question is that I want to understand how to implement a similar server, say, more than 1000 - 10 ... 000 people? If you can with examples. (Under the server we understand the program which may not be on the same station). So, one thread will contain the following functions: receiving JSON, decoding, search through the database, forming the response and sending it. And for each user, 1 such thread?

1 comment

Look better at D. In terms of idiom, it is almost like Java, but it does not require JVM and supports filebars, i.e. in Java you will run out of threads very quickly. Purely theoretically there are green threads in Java, but that's not exactly what you need.

4 Answers

by
4 votes
Use Netty
by
3 votes
No way!
To implement competitive queries from 100,000 onwards, it is worth looking at architectural patterns, paradigms, rather than programming languages.
No language can "take out" so much on one instance. And what if it (the server) is "down"?

2 Comments

Arthur :
Not really. The number of open threads is not a load criterion, because a thread has to be opened for every request.
But the requests are different in their nature and costs. So a simple, naive option is to https://ru.wikipedia.org/wiki/%D0%91%D0%B0%D0%BB%D...

One input, but there are N-number of handlers (servers). For such a scenario, there are many things to be considered. The most important one is that there is no stack in the request.
Not necessarily at one station, that is, when a certain number of threads at one station is reached, send a request for it to another station? I see.
by
2 votes
Exactly on this subject there is a video in which Heinz Kabutz explains everything in detail:
3 votes
A lot depends on "processing and searching. If you have this procedure fast and not demanding to memory, then 1000 queries per second Spring MVC will chew up without any additional manipulations. But if the processing of a single query is long, or there are 10,000 queries, then there is a problem C10k . Only an asynchronous server can help you with this. Or a cluster of servers with load balancing.