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


Java AsyncResponse.setTimeout方法代碼示例

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


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

示例1: addition

import javax.ws.rs.container.AsyncResponse; //導入方法依賴的package包/類
@POST
public void addition(@Suspended AsyncResponse response, JsonObject input) {
    response.setTimeout(500, TimeUnit.MILLISECONDS);
    response.setTimeoutHandler(this::handleTimeout);
    int a = ofNullable(input.getJsonNumber("a")).
            map(JsonNumber::intValue).
            orElseThrow(() -> new LackingParameterException("a"));
    int b = ofNullable(input.getJsonNumber("b")).
            map(JsonNumber::intValue).
            orElseThrow(() -> new LackingParameterException("b"));
    supplyAsync(() -> computeResult(a, b), mes).thenAccept(response::resume);
}
 
開發者ID:AdamBien,項目名稱:javaee-calculator,代碼行數:13,代碼來源:AdditionResource.java

示例2: s1

import javax.ws.rs.container.AsyncResponse; //導入方法依賴的package包/類
@ApiOperation(value = "Cancelling after 1 seconds",
    tags = "internal")
@GET
@Path("/s1")
@Produces(MediaType.TEXT_PLAIN)
public void s1(@Suspended final AsyncResponse asyncResponse) throws InterruptedException {

    asyncResponse.setTimeout(5, TimeUnit.SECONDS);
    Thread.sleep(1000);
    asyncResponse.cancel(5);
}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:12,代碼來源:HelloResource.java

示例3: st

import javax.ws.rs.container.AsyncResponse; //導入方法依賴的package包/類
@ApiOperation(value = "Timeout after 2 seconds")
@GET
@Path("/st")
@Produces(MediaType.TEXT_PLAIN)
public void st(@Suspended final AsyncResponse asyncResponse) throws InterruptedException {

    asyncResponse.setTimeout(1, TimeUnit.SECONDS);
    Thread.sleep(2000);
    asyncResponse.resume(Response.ok("hello").build());
}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:11,代碼來源:HelloResource.java

示例4: createUserAsync

import javax.ws.rs.container.AsyncResponse; //導入方法依賴的package包/類
@POST
public void createUserAsync(User user, @Suspended AsyncResponse response) {

    response.setTimeout(5, TimeUnit.SECONDS);
    response.setTimeoutHandler(r ->
            r.resume(Response.status(Response.Status.SERVICE_UNAVAILABLE)));

    mes.submit(() -> response.resume(createUser(user)));
}
 
開發者ID:PacktPublishing,項目名稱:Architecting-Modern-Java-EE-Applications,代碼行數:10,代碼來源:UsersResource.java

示例5: chocolates

import javax.ws.rs.container.AsyncResponse; //導入方法依賴的package包/類
@GET
public void chocolates(@Suspended AsyncResponse response) {
    response.setTimeout(2, TimeUnit.SECONDS);
    CompletableFuture.supplyAsync(store::get).thenAccept(response::resume);
}
 
開發者ID:AdamBien,項目名稱:live4code,代碼行數:6,代碼來源:ChocolatesResource.java

示例6: message

import javax.ws.rs.container.AsyncResponse; //導入方法依賴的package包/類
@GET
public void message(@Suspended AsyncResponse response) {
    response.setTimeout(2, TimeUnit.SECONDS);
    supplyAsync(this::get, mes).thenAccept(response::resume);
}
 
開發者ID:AdamBien,項目名稱:live4code,代碼行數:6,代碼來源:HelloResource.java

示例7: ping

import javax.ws.rs.container.AsyncResponse; //導入方法依賴的package包/類
@GET
public void ping(@Suspended AsyncResponse response) {
    response.setTimeout(1, TimeUnit.NANOSECONDS);
    System.out.println(".");
    response.resume("Java EE 8 is crazy fast!");
}
 
開發者ID:AdamBien,項目名稱:javaee-calculator,代碼行數:7,代碼來源:PingResource.java


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