Announcement Announcement Module
Collapse
No announcement yet.
RestTemplate / HttpAccessor seems to be leaking threads on Android Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RestTemplate / HttpAccessor seems to be leaking threads on Android

    Hi there,

    I am using RestTemplate from spring-android-rest-template 1.0.0.M4, which I construct on demand using
    Code:
    new RestTemplate();
    or
    Code:
    new RestTemplate(new SimpleClientHttpRequestFactory());
    Unfortunately, both constructors are leaking threads whose lifetime exceeds that of the respective RestTemplate instance as HttpAccessor has a private field that initializes a new HttpComponentsClientHttpRequestFactory anyway:

    Code:
    private ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    The spawned threads (one per RestTemplate instance) look like this:

    Code:
    Daemon Thread [<17> [email protected]@44eb3ce8] (Running)
    The threads are cleaned up in a finalizer, but given a sufficient amount of RestTemplate creations, the application will still crash due to a depletion of resources.

    Any idea?

    Thanks,
    Thilo
    Last edited by thilo.ginkel; Sep 26th, 2011, 01:42 AM.

  • #2
    Thilo, I've added a JIRA issue for this, and will plan a fix in the 1.0.0.RC1. Thanks for the feedback!

    https://jira.springsource.org/browse/ANDROID-61

    Comment


    • #3
      As I mentioned in the JIRA, we should probably default to SimpleClientHttpRequestFactory in Android 2.2 and newer, so the HttpComponentsClientHttpRequestFactory instance is not created. I'm also looking into switching from using the DefaultHttpClient to AndroidHttpClient which is a customized version of DefaultHttpClient for Android. Unfortunately, it is only available in Android 2.2, and we still need to support 2.1 in Spring Android.

      Comment

      Working...
      X