|
15 | 15 |
|
16 | 16 | import static org.asynchttpclient.util.Assertions.assertNotNull; |
17 | 17 | import static org.asynchttpclient.util.DateUtils.unpreciseMillisTime; |
18 | | -import io.netty.channel.Channel; |
19 | | -import io.netty.channel.ChannelId; |
20 | | -import io.netty.util.Timeout; |
21 | | -import io.netty.util.Timer; |
22 | | -import io.netty.util.TimerTask; |
23 | 18 |
|
24 | 19 | import java.net.InetSocketAddress; |
25 | 20 | import java.util.*; |
26 | 21 | import java.util.concurrent.ConcurrentHashMap; |
27 | 22 | import java.util.concurrent.ConcurrentLinkedDeque; |
28 | 23 | import java.util.concurrent.TimeUnit; |
29 | 24 | import java.util.concurrent.atomic.AtomicBoolean; |
| 25 | +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
30 | 26 | import java.util.function.Function; |
31 | 27 | import java.util.function.Predicate; |
32 | 28 | import java.util.stream.Collectors; |
|
36 | 32 | import org.slf4j.Logger; |
37 | 33 | import org.slf4j.LoggerFactory; |
38 | 34 |
|
| 35 | +import io.netty.channel.Channel; |
| 36 | +import io.netty.channel.ChannelId; |
| 37 | +import io.netty.util.Timeout; |
| 38 | +import io.netty.util.Timer; |
| 39 | +import io.netty.util.TimerTask; |
| 40 | + |
39 | 41 | /** |
40 | 42 | * A simple implementation of {@link ChannelPool} based on a {@link java.util.concurrent.ConcurrentHashMap} |
41 | 43 | */ |
@@ -106,17 +108,21 @@ private static final class ChannelCreation { |
106 | 108 | } |
107 | 109 |
|
108 | 110 | private static final class IdleChannel { |
| 111 | + |
| 112 | + private static final AtomicIntegerFieldUpdater<IdleChannel> ownedField = AtomicIntegerFieldUpdater.newUpdater(IdleChannel.class, "owned"); |
| 113 | + |
109 | 114 | final Channel channel; |
110 | 115 | final long start; |
111 | | - final AtomicBoolean owned = new AtomicBoolean(false); |
| 116 | + @SuppressWarnings("unused") |
| 117 | + private volatile int owned = 0; |
112 | 118 |
|
113 | 119 | IdleChannel(Channel channel, long start) { |
114 | 120 | this.channel = assertNotNull(channel, "channel"); |
115 | 121 | this.start = start; |
116 | 122 | } |
117 | 123 |
|
118 | 124 | public boolean takeOwnership() { |
119 | | - return owned.compareAndSet(false, true); |
| 125 | + return ownedField.getAndSet(this, 1) == 0; |
120 | 126 | } |
121 | 127 |
|
122 | 128 | public Channel getChannel() { |
|
0 commit comments