I have build an app where I used Okhttp and retrofit. Everything works fine except some irregular wired behaviour. In this news app I trigger feed download request for multiple sections. Time to time requests never return any response (not even throw exceptions) it just get stuck and in Logcat I see continuous garbage collections.
I tried to find potential suspect find can't find anything. Only thing I can see from "Threads" in ddms is that lots of Threads are in "monitor" state (please see the screenshot)
Edit: Another usual Thread dump for retrofit:
Here is the Retrofit config:
public interface ApiService {
@GET("/feed/get-news-feed/{section}")
void getNewsArticles(
@Path("section") String section,
Callback<GeneratedNewsEntryList> callback
);
}
public static ApiService getInstance() {
if(service == null) {
OkHttpClient okHttpClient = new OkHttpClient();
File cacheDir = App.getContext().getCacheDir();
HttpResponseCache cache = null;
try {
cache = new HttpResponseCache(cacheDir, 1024);
} catch (IOException e) {
e.printStackTrace();
}
okHttpClient.setResponseCache(cache);
RestAdapter restAdapter = new RestAdapter.Builder()
.setServer(BASE_URL)
.setClient(new OkClient(okHttpClient))
.setErrorHandler(new ErrorHandler() {
@Override
public Throwable handleError(RetrofitError arg0) {
if(arg0.getResponse().getStatus() == 404)
return new Exception("Url does not exists");
return new Exception(arg0.getMessage());
}
})
.build();
service = restAdapter.create(ApiService.class);
}
return service;
}
Any idea, anyone experience similar issues?