且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

异步的servlet处理如何提高性能

更新时间:2023-12-03 13:37:46

了解更多关于 Servlet的3 0的最终规格 - 2.3.3.3节 - 异步处理它的详细解释

Read more about Servlet 3 0 final-spec - Section 2.3.3.3 - Asynchronous processing where it is explained in detail.

这会使容器派遣一个线程,可能从管理线程池,运行指定的的Runnable AsyncContext 中的的Servlet 3.0规范的处理HTTP请求中定义的标准方式异步的。

It causes the container to dispatch a thread, possibly from a managed thread pool, to run the specified Runnable. AsyncContext is a standard way defined in Servlet 3.0 specification to handle HTTP requests asynchronously.

基本上HTTP请求不再依赖于一个HTTP线程的,让我们以后处理它,可能使用较少的线程。原来,该规范提供了一个API来处理异步线程的不同的线程池的开箱

Basically HTTP request is no longer tied to an HTTP thread, allowing us to handle it later, possibly using fewer threads. It turned out that the specification provides an API to handle asynchronous threads in a different thread pool out of the box.

了解更多关于 Executors.newFixedThreadPool() 创建一个可重用共享的***队列工作线程固定数量的线程池。在任何一点,顶多来确定nthreads线程将积极处理任务。如果当所有线程是活动的其他任务提交,他们将在队列中等待,直到某个线程可用。


Read more about Executors.newFixedThreadPool() that creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue. At any point, at most nThreads threads will be active processing tasks. If additional tasks are submitted when all threads are active, they will wait in the queue until a thread is available.

请看看 的ExecutorService 阅读更多关于它与样品code一起。

Please have a look at ExecutorService to read more about it along with sample code.