Javaサービスでretrofit2を使用して、REST APIに接続してデータを取得しています。Retrofit2 - OkHttp ConnectionPoolスレッドは100以上のスレッドになります。どうして?
コードは次のようになります。
Retrofit retrofit =
new Retrofit.Builder().baseUrl(endPoint).addConverterFactory(JacksonConverterFactory.create())
.build();
SyncCentralLojaProxySvc svc = retrofit.create(SyncCentralLojaProxySvc.class);
LogVerCentralLojaEntity entity = syncSvc.getLogVerByCdFilial(filial);
long cd_log = (entity != null) ? entity.getCdLog() : 0;
Call<LogCentralLojaCompactoCollectionDto> call = svc.getLogCompacto(filial, cd_log);
Response<LogCentralLojaCompactoCollectionDto> response = call.execute();
//NOT_MODIFIED
if (response.code() == 304) {
return 0;
}
if (!response.isSuccessful())
throw new IOException(response.errorBody().string());
LogCentralLojaCompactoCollectionDto body = response.body();
そのシンプルなデータは、それが数秒ごとに(ない並行して)同期動作しますフェッチ。
私は、VisualVMがOkHttpのトレードが大きくなりすぎていることに気付きました。このアプリケーションは100回の操作を並列に行うことはありません。実際には、1つだけ必要です。
これを調整するにはどうすればよいですか?非常に多くのスレッドを持つのは当然ですか?
キープアライブ期間では10秒がおそらく小さすぎます。 OkHttpはデフォルトでこれに5分を使用します。 –