File tree 1 file changed +8
-4
lines changed
src/main/java/com/fasterxml/jackson/core/util
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 5
5
6
6
import java .util .*;
7
7
import java .util .concurrent .ConcurrentHashMap ;
8
+ import java .util .concurrent .locks .ReentrantLock ;
8
9
9
10
/**
10
11
* For issue [jackson-core#400] We keep a separate Set of all SoftReferences to BufferRecyclers
@@ -23,7 +24,7 @@ class ThreadLocalBufferManager
23
24
* A lock to make sure releaseBuffers is only executed by one thread at a time
24
25
* since it iterates over and modifies the allSoftBufRecyclers.
25
26
*/
26
- private final Object RELEASE_LOCK = new Object ();
27
+ private final ReentrantLock RELEASE_LOCK = new ReentrantLock ();
27
28
28
29
/**
29
30
* A set of all SoftReferences to all BufferRecyclers to be able to release them on shutdown.
@@ -64,17 +65,20 @@ public static ThreadLocalBufferManager instance() {
64
65
* It will clear all bufRecyclers from the SoftRefs and release all SoftRefs itself from our set.
65
66
*/
66
67
public int releaseBuffers () {
67
- synchronized (RELEASE_LOCK ) {
68
- int count = 0 ;
68
+ int count = 0 ;
69
+ RELEASE_LOCK .lock ();
70
+ try {
69
71
// does this need to be in sync block too? Looping over Map definitely has to but...
70
72
removeSoftRefsClearedByGc (); // make sure the refQueue is empty
71
73
for (SoftReference <BufferRecycler > ref : _trackedRecyclers .keySet ()) {
72
74
ref .clear (); // possibly already cleared by gc, nothing happens in that case
73
75
++count ;
74
76
}
75
77
_trackedRecyclers .clear (); //release cleared SoftRefs
76
- return count ;
78
+ } finally {
79
+ RELEASE_LOCK .unlock ();
77
80
}
81
+ return count ;
78
82
}
79
83
80
84
public SoftReference <BufferRecycler > wrapAndTrack (BufferRecycler br ) {
You can’t perform that action at this time.
0 commit comments