Skip to content

Commit

Permalink
Use WeakHashMap in IdleConenctionReaper (#4087)
Browse files Browse the repository at this point in the history
* Use WeakHashMap in IdleConenctionReaper to not prevent connection manager from getting GC'd

* Checkstyle fix
  • Loading branch information
zoewangg authored Jun 9, 2023
1 parent a160498 commit 1605c52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-15df2d6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "feature",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "`IdleConnectionReaper` now does not prevent `HttpClientConnectionManager` from getting GC'd in the case where an SDK client is created per request and not closed."
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package software.amazon.awssdk.http.apache.internal.conn;

import java.time.Duration;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.WeakHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -48,7 +49,7 @@ public final class IdleConnectionReaper {
private volatile ReaperTask reaperTask;

private IdleConnectionReaper() {
this.connectionManagers = new ConcurrentHashMap<>();
this.connectionManagers = Collections.synchronizedMap(new WeakHashMap<>());

this.executorServiceSupplier = () -> {
ExecutorService e = Executors.newSingleThreadExecutor(r -> {
Expand Down

0 comments on commit 1605c52

Please sign in to comment.