




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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 codetrue.* 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* 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()到容器,或 AsynCplete ,则返回false./* Whether async request processing has completed.* 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 true 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);this.asyncContext.dispatch();/ -/ Implementation of AsyncListener methods/ -public void onStartAsync(AsyncEvent event) throws IOException public void onError(AsyncEvent event) throws IOException public void onTimeout(AsyncEvent event) throws IOException for (Runnable handler : this.timeoutHandlers) handler.run();public void onComplete(AsyncEvent event) throws IOException for (Runnable handler : pletionHandlers) handler.run();this.asyncContext = null;this.asyncCompleted.set(true);/设置异步处理已经完成NoSupportAsyncWebRequest.java不支持异步处理模式的web请求DeferredResultProcessingInterceptor.javaDeferredResult处理过程拦截器在start async前,超时后/异步处理完成后/网络超时后触发拦截DeferredResultProcessingInterceptorAdapter.java抽象类实现DeferredResultProcessingInterceptor,做空实现DeferredResultInterceptorChain.java调用DeferredResultProcessingInterceptor的辅助类DeferredResult.java递延结果,在两个线程中传递的对象结果实现Comparable接口以保证加入PriorityQueue队列的正确顺序CallableProcessingInterceptor.javaCallable拦截器CallableProcessingInterceptorAdapter.java抽象类实现CallableProcessingInterceptor接口,空实现CallableInterceptorChain.java调用CallableProcessingInterceptor的辅助类TimeoutCallableProcessingInterceptor.java继承CallableProcessingInterceptorAdapter实现超时处理方法TimeoutDeferredResultProcessingInterceptor.java继承DeferredResultProcessingInterceptorAdapter实现超时处理方法WebAsyncTask.javaweb异步任务包含一个Callable类,一个超时时间,一个任务执行着或名字WebAsyncUtils.java实现getAsyncManager实现createAsyncWebRequestWebAsyncManager.java对Callables和DeferredResults启动的管理,包括拦截器的注入,Excutor的注入等异步处理的
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年简易合租合同范本下载
- 2025年国内合作企业合同范本
- 2025年电子产品采购合同模板
- 2025合同争议仲裁申请书格式范文
- 艺术学的研究之旅
- 2025 年土地使用权互换合同范本
- 舞美设计师核心能力体系
- 2025健身器材购置合同
- 2025企业租赁管理合同模板
- 新中式别墅设计全解析
- 湘教版高中地理必修二区域发展战略教学课件
- 《建筑工程概算》课件
- 年产16万吨赤藓糖醇项目建议书
- 基层综合治理法律培训课件
- 三轴搅拌桩验收要求
- 2024年云南交投集团招聘笔试参考题库含答案解析
- 高大支架坍塌事故原因分析及预防措施
- 跨境数据传输与安全保护
- 制衣厂安全隐患排查项目清单及排查表
- ISO13485质量管理手册
- 辩论赛PPT模板模板
评论
0/150
提交评论