由servlet请求的异步处理 [英] Asynchronous processing of Requests by Servlet

查看:131
本文介绍了由servlet请求的异步处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到由Servlet的请求的异步处理,因为我是一个探索应用的NodeJS和Java应用程序如何处理一个请求。

I came across the Asynchronous processing of requests by Servlets, as I was exploring how a NodeJS application and a Java application handles a request.

这是我在不同的地方已经阅读:

From what I have read in different places:

请求将从Servlet容器和阻塞操作(如I / O),请求可以切换到另一个线程池和接收请求可以去HTTP线程的情况下,接收和处理通过HTTP线程回收到并处理下一个请求。

The request will be received and processed by a HTTP thread from the Servlet Container and in case of blocking operations (like I/O), the request can be handed over to another Threadpool and the HTTP thread which received the request can go back to receive and process the next request.

的费时阻塞操作现在将通过从线程池的工人进行讨论。

The time-consuming blocking operation will now be taken up by a worker from the Threadpool.

如果我明白了什么是正确的,我有以下问题:

If what I had understood is correct, I have the following question:

即使是处理阻塞操作是要等待操作完成,从而阻断资源(以及处理的线程的数目等于核的数量),如果我右螺纹。

Even the thread that processes the blocking operation is going to wait for that operation to complete and hence blocking the resources(and number of threads processed is equal to the number of cores), if I am right.

究竟是采用异步处理,这里的收获?

What exactly is the gain here by using of asynchronous processing?

如果没有,开导我请。

If not, enlighten me please.

推荐答案

是的,在这种情况下阻塞操作将在它自己的线程中执行,将被阻挡一些资源,但你的HTTP线程现在可以自由地处理一些其它操作可能是不那么耗时。

Yes, in this scenario blocking operation will execute in it's own thread and will be blocking some resources, but your HTTP thread is now free to process some other operations that might be not so time-consuming.

您异步处理的增益是继续处理其他请求,同时等待重量级的操作反应,而不是愚蠢的拦截HTTP线程的能力。

Your gain of asynchronous processing is ability to continue handling other requests while waiting heavyweight operation response instead of dumb blocking HTTP thread.

这篇关于由servlet请求的异步处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆