Spring Servlet3 扩展模块笔记
Servlet 3.0AsyncWebRequest.java异步请求接口,继承NativeWebRequest接口[java]* Set the time required for concurrent handling to complete.* This property should not be set when concurrent handling is in progress,* i.e. when {@link #isAsyncStarted()} is {@code true}.* @param timeout amount of time in milliseconds; {@code null} means no* timeout, i.e. rely on the default timeout of the container.*///设置超时时间void setTimeout(Long timeout);/*** Add a handler to invoke when concurrent handling has timed out.*///增加超时处理类void addTimeoutHandler(Runnable runnable);/*** Add a handle to invoke when request processing completes.*///增加请求处理完成处理类void addCompletionHandler(Runnable runnable);/*** Mark the start of asynchronous request processing so that when the main* processing thread exits, the response remains open for further processing* in another thread.* @throws IllegalStateException if async processing has completed or is not supported*///标示异步请求开始,返回异步Contextvoid startAsync();/*** Whether the request is in async mode following a call to {@link #startAsync()}.* Returns "false" if asynchronous processing never started, has completed,* or the request was dispatched for further processing.*///判断是否是当前线程是否启动异步模式,false表示没有启动异步模式,或者已经完成,否则请求被分发到其他线程处理boolean isAsyncStarted();/*** Dispatch the request to the container in order to resume processing after* concurrent execution in an application thread.*///分发请求到容器,唤醒其他线程处理void dispatch();/*** Whether asynchronous processing has completed.*///判断异步处理是否完成boolean isAsyncComplete();StandardServletAsyncWebRequest.java继承ServletWebRequest,实现AsyncWebRequest, AsyncListener,一个标准异步web请求的实现类。代码[java] view plaincopy/*** {@inheritDoc}* <p>In Servlet 3 async processing, the timeout period begins after the* container processing thread has exited.*/public void setTimeout(Long timeout) {Assert.state(!isAsyncStarted(), "Cannot change the timeout with concurrent handling in progress");//断言状态没有启动异步this.timeout = timeout;}public boolean isAsyncStarted() {return ((this.asyncContext != null) && getRequest().isAsyncStarted());//异步状态不为空,请求是否启动异步处理模式,如果请求被AsyncContext.dispatch()到容器,或 AsynContext.complete ,则返回false.}/*** Whether async request processing has completed.* <p>It is important to avoid use of request and response objects after async* processing has completed. Servlet containers often re-use them.*/public boolean isAsyncComplete() {return this.asyncCompleted.get();//请求的异步处理是否完成}public void startAsync() {Assert.state(getRequest().isAsyncSupported(),"Async support must be enabled on a servlet and for all filters involved " +"in async request processing. This is done in Java code using the Servlet API " +"or by adding \"<async-supported>true</async-supported>\" to servlet and " +"filter declarations inweb.xml.");//判断请求是否支持异步处理Assert.state(!isAsyncComplete(), "Async processing has already completed");if (isAsyncStarted()) {//判断状态是否已经启动异步处理模式return;}this.asyncContext = getRequest().startAsync(getRequest(), getResponse());this.asyncContext.addListener(this);if (this.timeout != null) {this.asyncContext.setTimeout(this.timeout);}}public void dispatch() {Assert.notNull(this.asyncContext, "Cannot dispatch without an AsyncContext");补充:软件开发 , Java ,
上一个:java 特性详解
下一个:Core Java小练习 - 反转文字
- 更多JAVA疑问解答:
- java怎么在线读取ftp服务器上的文件内容
- 关于程序员的职业规划
- HTML和JSP矛盾吗?
- java小程序如何打包?
- java怎么split路径文件名?
- 关于Hibernate实体自身多对一的抓取问题
- 关于apache2+tomcat群集出现的问题
- SSH 导入导出excel 谁有这块的资料吗?
- springmvc 加载一个jsp页面执行多个方法 报404
- 关于用jquery 导入 excel
- java对时间进行循环放到List中
- 一个图片的输入输出程序,第一次调用某方法会中断,第二次调用则正常
- 请上过传智播客的人说一下传智播客怎么样呀!是不是像它说的那样好呀!
- spring的schema怎么配置
- 【菜鸟求助】SSH中怎么从JSP页面往后台传值呢