本文整理汇总了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();
}
}
});
}
示例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();
}
});
}
示例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();
});
}
示例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();
}
}
}
});
}