Notes for Spring Servlet3 extension module

Source: Internet
Author: User

Servlet 3.0AsyncWebRequest.java asynchronous request interface, inherited from NativeWebRequest interface [java] * Set the time required for concurrent handling to complete. * This property shoshould 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. * /// set timeout Void setTimeout (Long timeout);/*** Add a handler to invoke when concurrent handling has timed out. * // added the timeout processing class void addTimeoutHandler (Runnable runnable);/*** Add a handle to invoke when request processing completes. * // added the void addCompletionHandler (Runnable runnable) class for processing completed requests;/*** Mark the start of asynchronous request processing so that when the main * processing thread exits, the respo Neuron remains open for further processing * in another thread. * @ throws IllegalStateException if async processing has completed or is not supported * // indicates the start of the asynchronous request and returns the asynchronous Context void 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 pro Cessing. * // determine whether the current thread starts the asynchronous mode. false indicates that the asynchronous mode is not started or has been completed. Otherwise, the request is distributed to other threads to process boolean isAsyncStarted (); /*** Dispatch the request to the container in order to resume processing after * concurrent execution in an application thread. * // dispatch the request to the container and wake up other threads to process void dispatch ();/*** Whether asynchronous processing has completed. * /// determine whether the asynchronous processing is completed boolean isAsyncComplete (); StandardServletAsyncWebRequest. java inherits Se RvletWebRequest implements AsyncWebRequest, AsyncListener, and a standard asynchronous web request implementation class. Code [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"); // the assertion State does not start Asynchronous this. timeout = timeout;} public boolean isAsyncStarted () {return (this. asyncContext! = Null) & getRequest (). isAsyncStarted (); // whether the asynchronous processing mode is enabled for the request if the request is in AsyncContext. dispatch () to the container, or AsynContext. complete, false is returned .} /*** 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 (); // Whether the asynchronous processing of the request is complete} 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 in web. xml. "); // determines whether the request supports Assert asynchronous processing. state (! IsAsyncComplete (), "Async processing has already completed"); if (isAsyncStarted () {// determines whether the status has started the asynchronous processing mode 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 ();} // implements // Implementation of AsyncListener methods // implements 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: this. completionHandlers) {handler. run ();} this. asyncContext = null; this. asyncCompleted. set (true); // set that asynchronous processing has been completed} NoSupportAsyncWebRequest. java does not support DeferredResultProcessingInterceptor in asynchronous processing mode. java DeferredResult: the interceptor triggers the interception of DeferredResultProcessingInterceptorAdapter before start async, after timeout, after asynchronous processing, or after network timeout. java Abstract class implements DeferredResultProcessingInterceptor, and short implements DeferredResultInterceptorChain. java calls DeferredResultProcessingInterceptor's helper class DeferredResult. java deferred results: the Comparable interface is implemented for the object results passed in the two threads to ensure that the correct order CallableProcessingInterceptor is added to the PriorityQueue queue. javaCallable interceptor CallableProcessingInterceptorAdapter. java Abstract class implements the CallableProcessingInterceptor interface, and empty implement CallableInterceptorChain. java calls the auxiliary class TimeoutCallableProcessingInterceptor of CallableProcessingInterceptor. java inherits CallableProcessingInterceptorAdapter to implement TimeoutDeferredResultProcessingInterceptor. java inherits DeferredResultProcessingInterceptorAdapter to implement the timeout processing method WebAsyncTask. A java web asynchronous task contains a Callable class, a time-out period. A task is executed or named WebAsyncUtils. java implements getAsyncManager to implement createAsyncWebRequestWebAsyncManager. java manages Callables and DeferredResults startup, including interceptor injection, Excutor injection, and other asynchronous processing entry classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.