madguy
madguy

Reputation: 45

Multithreaded Web Application vs Multithreaded Web Server

I have recently started working with Java based web applications. Can anyone help me understand difference between a Multithreaded Web Application and a Multithreaded Web Server?

Request you to give some scenarios where the above 2 entities are helpful.

Also, I have a web application which is expected to use a ThreadPool to process incoming requests. After processing each request, it returns a proper http response which is consumed by another application. In this scenario, should the application be multithreaded or the server? Using multithreading in the web application, I faced that the responses were getting mixed due to network/processing delay.

Thanks

Upvotes: 0

Views: 302

Answers (1)

flup
flup

Reputation: 27104

If you want to process the incoming requests asynchronously, the request arrives at a server thread, then gets transferred to an application thread from your threadpool. When the result becomes available, the corresponding request needs to be found and the answer sent back to that client.

Look at a server setup that uses nio. See for instance https://today.java.net/pub/a/today/2007/02/13/architecture-of-highly-scalable-nio-server.html and https://hc.apache.org/httpcomponents-core-ga/tutorial/html/nio.html

This way an incoming request won't keep a server thread busy until the answer becomes available.

Upvotes: 2

Related Questions