thilo.ginkel
Sep 25th, 2011, 07:23 AM
Hi there,
I am using RestTemplate from spring-android-rest-template 1.0.0.M4, which I construct on demand using
new RestTemplate();
or
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:
private ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
The spawned threads (one per RestTemplate instance) look like this:
Daemon Thread [<17> RefQueueWorker@org.apache.http.impl.conn.tsccm.Con nPoolByRoute@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
I am using RestTemplate from spring-android-rest-template 1.0.0.M4, which I construct on demand using
new RestTemplate();
or
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:
private ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
The spawned threads (one per RestTemplate instance) look like this:
Daemon Thread [<17> RefQueueWorker@org.apache.http.impl.conn.tsccm.Con nPoolByRoute@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