Servlet 3.0异步 [英] Servlet 3.0 asynchronous

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

问题描述

servlet 3.0异步功能之间的区别是什么:

What's the diffrent between servlet 3.0 asynchronous feature against:

old servlet impl
doGet(request,response) {
Thread t = new Thread(new Runnable()
     void run(){
        // heavy processing
        response.write(result)
     }
}
t.start();

如果我浪费线程到servlet 3.0做重处理 - 我在容器中又多了一个线程,但是我把它浪费在繁重的处理中...... :(

In servlet 3.0 if I waste a thread to do heavy processing - I earn one more thread in the container, but I waste it in heavy processing... :(

有人可以帮忙吗?

推荐答案

这不起作用。一旦 doGet 方法结束,响应就完成并发送回到客户端。您的线程可能仍在运行,但它不能再更改响应。

This won't work. Once your doGet method ends, the response is complete and sent back to the client. Your thread may or may not still be running, but it can't change the response any longer.

Servlet 3.0中的新异步功能是什么,它是否允许您释放请求线程以处理另一个请求。会发生以下情况:

What the new async feature in Servlet 3.0 does, is that it allows you to free the request thread for processing another request. What happens is the following:

RequestThread:  |-- doGet() { startAsync() }  // Thread free to do something else
WorkerThread:                 |-- do heavy processing --|
OtherThread:                                            |-- send response --|

重要的是,一旦 RequestThread 已经通过调用 startAsync(...)启动异步处理,可以自由地做其他事情。例如,它可以接受新请求。这提高了吞吐量。

The important thing is that once RequestThread has started asynchronous processing via a call to startAsync(...), it is free to do something else. It can accept new requests, for example. This improves throughput.

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

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