Skip to content

Commit

Permalink
fix unnecessary threadpool-creation
Browse files Browse the repository at this point in the history
New OkHttpClients came with their own thread and connection pools. With newBuilder() we can create a new client with an already existing pool.

Fixes signalapp/Signal-Android#6283
  • Loading branch information
Trolldemorted committed May 11, 2017
1 parent 2154ae4 commit 14215c3
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
public class PushServiceSocket {

private static final String TAG = PushServiceSocket.class.getSimpleName();
private static final OkHttpClient CLIENT = new OkHttpClient();

private static final String CREATE_ACCOUNT_SMS_PATH = "/v1/accounts/sms/code/%s";
private static final String CREATE_ACCOUNT_VOICE_PATH = "/v1/accounts/voice/code/%s";
Expand Down Expand Up @@ -612,7 +613,7 @@ private Response getConnection(String urlFragment, String method, String body)
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, null);

OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder()
OkHttpClient.Builder okHttpClientBuilder = CLIENT.newBuilder()
.sslSocketFactory(context.getSocketFactory(), (X509TrustManager)trustManagers[0])
.connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS)
.readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS);
Expand Down

0 comments on commit 14215c3

Please sign in to comment.