abhishekagarwal87 commented on a change in pull request #12298:
URL: https://github.com/apache/druid/pull/12298#discussion_r820660944



##########
File path: 
core/src/main/java/org/apache/druid/java/util/http/client/pool/ResourcePool.java
##########
@@ -212,15 +259,21 @@ V get()
         if (closed) {
           log.info(StringUtils.format("get() called even though I'm closed. 
key[%s]", key));
           return null;
-        } else if (!resourceHolderList.isEmpty()) {
-          ResourceHolder<V> holder = resourceHolderList.removeFirst();
-          if (System.currentTimeMillis() - holder.getLastAccessedTime() > 
unusedResourceTimeoutMillis) {
-            factory.close(holder.getResource());
+        } else if (numLentResources + deficit < maxSize) {
+          // Attempt to take an existing resource or create one if list is 
empty
+          if (resourceHolderList.isEmpty()) {
             poolVal = factory.generate(key);
           } else {
-            poolVal = holder.getResource();
+            ResourceHolder<V> holder = resourceHolderList.removeFirst();
+            if (System.currentTimeMillis() - holder.getLastAccessedTime() > 
unusedResourceTimeoutMillis) {
+              factory.close(holder.getResource());

Review comment:
       deficit should be incremented here too if there is an exception in 
regenerating the source. In fact the whole thing can be moved outside 
synchronized block. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to