Click here to Skip to main content
15,672,482 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have HTTP client:

OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(55, TimeUnit.MINUTES) // connect timeout
            .writeTimeout(55, TimeUnit.MINUTES) // write timeout
            .readTimeout(55, TimeUnit.MINUTES) // read timeout
    RequestBody body = RequestBody.create(json, JSON);
    Request request = new Request.Builder()
    try (Response response = client.newCall(request).execute()) {
        return response.body().string();
    } catch (IOException e) {

And one put method on the server (implemented in Spark):

put("/putMethod", (request, response) -> {
    try {
    catch (Exception e) {
    return "text";

The problem: when I set up for example TimeUnit.MINUTES.sleep(10) everything is fine I see return value "text". But when I set up TimeUnit.MINUTES.sleep(20) or longer I do not see return value also I do not see any errors, my client is just waiting and waiting. Do you have any idea what happen ?

What I have tried:

Tried to set up connection timeout - does not work
Updated 13-Jul-21 4:12am
Richard Deeming 14-Jul-21 3:55am    
The obvious question would be why? Keeping connections to your server open for that long is only going to drain your server's resources. After a while, no new connections will be made, since your server's "pending requests" queue will be full.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900