简体   繁体   English

多线程Web应用程序与多线程Web服务器

[英]Multithreaded Web Application vs Multithreaded Web Server

I have recently started working with Java based web applications. 我最近开始使用基于Java的Web应用程序。 Can anyone help me understand difference between a Multithreaded Web Application and a Multithreaded Web Server? 任何人都可以帮我理解多线程Web应用程序和多线程Web服务器之间的区别吗?

Request you to give some scenarios where the above 2 entities are helpful . 请求您提供上述2个实体有用的方案

Also, I have a web application which is expected to use a ThreadPool to process incoming requests. 此外,我有一个Web应用程序,预计将使用ThreadPool来处理传入的请求。 After processing each request, it returns a proper http response which is consumed by another application. 处理完每个请求后,它会返回一个正确的http响应,该响应由另一个应用程序使用。 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. 在Web应用程序中使用多线程,我遇到了由于网络/处理延迟而导致响应混乱的问题。

Thanks 谢谢

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. 查看使用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 例如参见https://today.java.net/pub/a/today/2007/02/13/architecture-of-highly-scalable-nio-server.htmlhttps://hc.apache.org/httpcomponents -core-GA /教程/ HTML / nio.html

This way an incoming request won't keep a server thread busy until the answer becomes available. 这样,传入请求将不会使服务器线程忙,直到答案可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM