java servlet 容器是否能够在没有额外线程的情况下进行异步 I/O 处理?
Are java servlet containers capable of asynchronous I/O processing without additional threads?
对于 Node.js 和 ASP.NET Core 等框架,它们能够异步处理 I/O 任务的请求,而无需创建额外的线程。 java servlet 容器也能做到这一点吗?如果没有,java servlet 容器是否会在线程中等待 I/O 个任务,直到请求被完全处理?
好的,我自己找到了答案。
根据Jakarta EE 9 documentation,:
There are two common scenarios in which a thread associated with a request can be sitting idle.
The thread needs to wait for a resource to become available or process data before building the response. For example, an application may need to query a database or access data from a remote web service before generating the response.
The thread needs to wait for an event before generating the response. For example, an application may have to wait for a Jakarta Messaging message, new information from another client, or new data available in a queue before generating the response.
These scenarios represent blocking operations that limit the scalability of web applications. Asynchronous processing refers to assigning these blocking operations to a new thread and retuning the thread associated with the request immediately to the container.
因此,java servlet 容器能够进行异步处理。然而,他们将为 I/O 和 CPU bond 任务创建新线程,这与 Node.js 和 ASP.NET 核心不同。
对于 Node.js 和 ASP.NET Core 等框架,它们能够异步处理 I/O 任务的请求,而无需创建额外的线程。 java servlet 容器也能做到这一点吗?如果没有,java servlet 容器是否会在线程中等待 I/O 个任务,直到请求被完全处理?
好的,我自己找到了答案。
根据Jakarta EE 9 documentation,:
There are two common scenarios in which a thread associated with a request can be sitting idle.
The thread needs to wait for a resource to become available or process data before building the response. For example, an application may need to query a database or access data from a remote web service before generating the response.
The thread needs to wait for an event before generating the response. For example, an application may have to wait for a Jakarta Messaging message, new information from another client, or new data available in a queue before generating the response.
These scenarios represent blocking operations that limit the scalability of web applications. Asynchronous processing refers to assigning these blocking operations to a new thread and retuning the thread associated with the request immediately to the container.
因此,java servlet 容器能够进行异步处理。然而,他们将为 I/O 和 CPU bond 任务创建新线程,这与 Node.js 和 ASP.NET 核心不同。