为了真正实现异步Servlet,不仅仅需要新开一个线程运行一个请求业务,还要做一个回调接口,给业务去调用,将返回的数据写回客户端,这样,在前段看来就达到异步的效果了。
Servlet关键代码:
AsyncContext ctx = request.startAsync(request, response);
ctx.start(new Executor(ctx));
Executor代码:
package com.vip.osp.restful.servlet;
import java.io.IOException;
import javax.servlet.AsyncContext;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.vip.osp.core.idl.metadata.Service;
import com.vip.osp.restful.entity.RestData;
import com.vip.osp.restful.match.Url2ServiceTable;
import com.vip.osp.restful.match.Url2ServiceUtils;
import com.vip.osp.restful.service.impl.OspRestfulSVImpl;
public class Executor implements AsyncCallBack {
private AsyncContext ctx = null;
public Execu