0

I'm using Jersey core client to connect to external services. I want to know the default timeout setting in Jersey. Any idea? I'm using Jersey 2.26.

Thanks and regards.

Note that I'm not asking how to set timeout for Jersey client, which already had good answers here: How to set the connection and read timeout with Jersey 2.x?

I only concern about knowing the default timeout value. Thanks.

Bruce Jia
  • 3
  • 1
  • 1
  • 6
  • This might help you https://stackoverflow.com/questions/19543209/how-to-set-the-connection-and-read-timeout-with-jersey-2-x – Ryuzaki L Jul 04 '18 at 02:44
  • Possible duplicate of [How to set the connection and read timeout with Jersey 2.x?](https://stackoverflow.com/questions/19543209/how-to-set-the-connection-and-read-timeout-with-jersey-2-x) – Ryuzaki L Jul 04 '18 at 02:44
  • The default read timeout in TCP is infinity, and the default connect timeout is the platform's operating system default, which is usually around a minute (often misdescribed in API documentation as 'infinite': it isn't). I would expect Jersey and every other API to follow suit. – user207421 Jul 04 '18 at 02:54

2 Answers2

7

According to doc in jersey api docs, the READ_TIMEOUT and CONNECT_TIMEOUT in client are both 0(infinity) in default.

Pavel
  • 318
  • 3
  • 13
Azarea
  • 516
  • 7
  • 22
0

According to Jersey docs

By default, there is no timeout defined i.e. a client has a read and connect timeout of infinity.

please refer https://jersey.github.io/documentation/latest/async.html#d0e9989

In case you want to set the timeout you can refer the below snippet from Jersey documentation

@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();
}
user207421
  • 305,947
  • 44
  • 307
  • 483
Sagar Kharab
  • 369
  • 2
  • 18