Skip to content

Instantly share code, notes, and snippets.

@bexp
Created June 2, 2016 22:38
Show Gist options
  • Save bexp/90d788ed58055d750a9f590502b8960c to your computer and use it in GitHub Desktop.
Save bexp/90d788ed58055d750a9f590502b8960c to your computer and use it in GitHub Desktop.
private final OkHttpClient client;
public ConfigureTimeouts() throws Exception {
client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
}
public void run() throws Exception {
Request request = new Request.Builder()
.url("http://httpbin.org/delay/2") // This URL is served with a 2 second delay.
.build();
Response response = client.newCall(request).execute();
System.out.println("Response completed: " + response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment