當前位置: 首頁>>代碼示例>>Java>>正文


Java AsyncContext.start方法代碼示例

本文整理匯總了Java中javax.servlet.AsyncContext.start方法的典型用法代碼示例。如果您正苦於以下問題:Java AsyncContext.start方法的具體用法?Java AsyncContext.start怎麽用?Java AsyncContext.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.AsyncContext的用法示例。


在下文中一共展示了AsyncContext.start方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doGet

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException {

    final AsyncContext asyncContext =
        request.startAsync(request, response);

    asyncContext.addListener(new TrackingListener(false, false, null));

    asyncContext.start(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(THREAD_SLEEP_TIME);
                TestAsyncContextImpl.track("Runnable-");
                asyncContext.complete();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:25,代碼來源:TestAsyncContextImpl.java

示例2: doPut

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
protected void doPut(HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    final AsyncContext ac = req.startAsync();
    ac.start(new Runnable() {
        @Override
        public void run() {
            resp.setContentType("text/plain");
            resp.setCharacterEncoding("UTF-8");
            try {
                resp.getWriter().print("OK");
            } catch (IOException e) {
                // Should never happen. Test will fail if it does.
            }
            ac.complete();
        }
    });
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:19,代碼來源:TestAbstractHttp11Processor.java

示例3: doGet

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  final String uuid = request.getParameter(UUID_PARAM);
  final AsyncContext acontext = request.startAsync();
  acontext.start(() -> {
    HttpServletResponse httpServletResponse = (HttpServletResponse) acontext.getResponse();
    try {
      System.out.println("Sleeping");
      Thread.sleep(5000);
      System.out.println("DONE Sleeping");
      httpServletResponse.getOutputStream().write(uuid.getBytes());
    } catch (InterruptedException | IOException | RuntimeException e) {
      try {
        httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
    System.out.println("completing");
    acontext.complete();
  });
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:24,代碼來源:AsyncServlet.java

示例4: doGet

import javax.servlet.AsyncContext; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    final AsyncContext asyncContext = request.startAsync(request, response);

    // TODO: This could be avoided by using an OpenTracing aware Runnable (when available)
    final Span cont = tracer.activeSpan();

    asyncContext.start(new Runnable() {
        @Override
        public void run() {
            HttpServletResponse asyncResponse = (HttpServletResponse) asyncContext.getResponse();
            try (Scope activeScope = tracer.scopeManager().activate(cont, false)) {
                try {
                    Thread.sleep(ASYNC_SLEEP_TIME_MS);
                    asyncResponse.setStatus(204);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    asyncResponse.setStatus(500);
                } finally {
                    asyncContext.complete();
                }
            }
        }
    });
}
 
開發者ID:opentracing-contrib,項目名稱:java-web-servlet-filter,代碼行數:28,代碼來源:AbstractJettyTest.java


注:本文中的javax.servlet.AsyncContext.start方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。