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

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


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

Java
put("/putMethod", (request, response) -> {
 
    try {
 
        TimeUnit.MINUTES.sleep(22);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    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
Posted
Updated 13-Jul-21 4:12am
v2
Comments
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