如何在 Jersey 客户端中获取默认超时
How to get the default timeout in Jersey client
我正在使用 Jersey 核心客户端连接到外部服务。我想知道 Jersey 中的默认超时设置。任何的想法?我正在使用 Jersey 2.26。
感谢和问候。
请注意,我不是在问如何为 Jersey 客户端设置超时,这里已经有很好的答案:How to set the connection and read timeout with Jersey 2.x?
我只关心知道默认超时值。谢谢
根据 Jersey 文档
By default, there is no timeout defined i.e. a client has a read and connect timeout of infinity.
请参考https://jersey.github.io/documentation/latest/async.html#d0e9989
如果您想设置超时,您可以参考 Jersey 文档中的以下片段
@GET
public void asyncGetWithTimeout(@Suspended final AsyncResponse asyncResponse) {
asyncResponse.setTimeoutHandler(new TimeoutHandler() {
@Override
public void handleTimeout(AsyncResponse asyncResponse) {
asyncResponse.resume(Response.status(Response.Status.SERVICE_UNAVAILABLE)
.entity("Operation time out.").build());
}
});
asyncResponse.setTimeout(20, TimeUnit.SECONDS);
new Thread(new Runnable() {
@Override
public void run() {
String result = veryExpensiveOperation();
asyncResponse.resume(result);
}
private String veryExpensiveOperation() {
// ... very expensive operation that typically finishes within 20 seconds
}
}).start();
}
根据jersey api docs中的文档,客户端中的READ_TIMEOUT和CONNECT_TIMEOUT默认都是0(无穷大)。
我正在使用 Jersey 核心客户端连接到外部服务。我想知道 Jersey 中的默认超时设置。任何的想法?我正在使用 Jersey 2.26。
感谢和问候。
请注意,我不是在问如何为 Jersey 客户端设置超时,这里已经有很好的答案:How to set the connection and read timeout with Jersey 2.x?
我只关心知道默认超时值。谢谢
根据 Jersey 文档
By default, there is no timeout defined i.e. a client has a read and connect timeout of infinity.
请参考https://jersey.github.io/documentation/latest/async.html#d0e9989
如果您想设置超时,您可以参考 Jersey 文档中的以下片段
@GET
public void asyncGetWithTimeout(@Suspended final AsyncResponse asyncResponse) {
asyncResponse.setTimeoutHandler(new TimeoutHandler() {
@Override
public void handleTimeout(AsyncResponse asyncResponse) {
asyncResponse.resume(Response.status(Response.Status.SERVICE_UNAVAILABLE)
.entity("Operation time out.").build());
}
});
asyncResponse.setTimeout(20, TimeUnit.SECONDS);
new Thread(new Runnable() {
@Override
public void run() {
String result = veryExpensiveOperation();
asyncResponse.resume(result);
}
private String veryExpensiveOperation() {
// ... very expensive operation that typically finishes within 20 seconds
}
}).start();
}
根据jersey api docs中的文档,客户端中的READ_TIMEOUT和CONNECT_TIMEOUT默认都是0(无穷大)。