@@ -158,9 +158,12 @@ public boolean offer(String uri, Channel channel) {
158
158
int size = idleConnectionForHost .size ();
159
159
if (maxConnectionPerHost == -1 || size < maxConnectionPerHost ) {
160
160
IdleChannel idleChannel = new IdleChannel (uri , channel );
161
- added = idleConnectionForHost .add (idleChannel );
162
- if (channel2IdleChannel .put (channel , idleChannel ) != null ) {
163
- log .error ("Channel {} already exists in the connections pool!" , channel );
161
+ synchronized (idleConnectionForHost ) {
162
+ added = idleConnectionForHost .add (idleChannel );
163
+
164
+ if (channel2IdleChannel .put (channel , idleChannel ) != null ) {
165
+ log .error ("Channel {} already exists in the connections pool!" , channel );
166
+ }
164
167
}
165
168
} else {
166
169
log .debug ("Maximum number of requests per host reached {} for {}" , maxConnectionPerHost , uri );
@@ -183,8 +186,12 @@ public Channel poll(String uri) {
183
186
boolean poolEmpty = false ;
184
187
while (!poolEmpty && idleChannel == null ) {
185
188
if (idleConnectionForHost .size () > 0 ) {
186
- idleChannel = idleConnectionForHost .poll ();
187
- if (idleChannel != null ) channel2IdleChannel .remove (idleChannel .channel );
189
+ synchronized (idleConnectionForHost ) {
190
+ idleChannel = idleConnectionForHost .poll ();
191
+ if (idleChannel != null ) {
192
+ channel2IdleChannel .remove (idleChannel .channel );
193
+ }
194
+ }
188
195
}
189
196
190
197
if (idleChannel == null ) {
0 commit comments