当前位置: 首页>>代码示例>>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;未经允许,请勿转载。