本文整理匯總了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();
}
}
}
});
}