Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

java - What's the purpose of async-supported in web.xml?

<servlet>
        <description>xxx</description>
        <servlet-name>xxx</servlet-name>
        <servlet-class>com.xxx.yyy</servlet-class>
        <async-supported>true</async-supported>
</servlet>

What's the purpose of async-supported in the servlet's web.xml configuration file? What case I can use it in?

question from:https://stackoverflow.com/questions/9919831/whats-the-purpose-of-async-supported-in-web-xml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ironically, I was looking for the syntax of how to write this property in tomcat's web.xml and this is the first search item I opened from google - it's written correctly too (it works), so thanks.

To answer your question though, this allows the servlet to store incoming requests for later response. It frees up the thread used to handle the request so it can be used elsewhere until the server is ready to send the response.

For practical purposes, with this configuration you can set-up a servlet that will (in effect) push data to the client (after the client sends the initial request to the server).

This technique replaces the need for unnecessary timed requests from a client to get data that can change at uncertain intervals. And it does it in a scalable manner by not hanging onto the thread.


Some example use-cases include:

Chat applications, when one client types a message you want it to appear instantly to the other client.

Email apps, to allow clients to view e-mails as soon as they are received by the e-mail server.

I've also used it to send input change updates to a browser from a Programming Logic Controller for automation tasks.

Here's a good tutorial on it. This also covers some nut and bolts in java.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...