jira-importer opened a new issue, #1287:
URL: https://github.com/apache/httpcomponents-core/issues/1287

   
**[marsqing](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=JIRAUSER300270)**
 opened 
**[HTTPCORE-746](https://issues.apache.org/jira/browse/HTTPCORE-746?redirect=false)**
 and commented
   
   [Virtual Threads](https://openjdk.org/jeps/444) is expected to be released 
in JDK21 soon. Contrast to traditional 'platform threads', virtual threads will 
usually unmount from platform threads when doing blocking operations. But 
accoring to the doc above, when doing blocking operations in synchronized 
block/method, the carrying platform thread will be pinned and can not carry 
other virtual threads.
   
    
   
   This limitation will make the sample in the attachment deadlocked. Because 
all the platform threads add pinned in 
[await](https://github.com/apache/httpcomponents-core/blob/45d8a4cb391f591bb8d380b820437b651435774f/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java#LL391C30-L391C30)
 because it is in a  [synchronized 
block](https://github.com/apache/httpcomponents-core/blob/45d8a4cb391f591bb8d380b820437b651435774f/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java#L244)
 and no connection is available in the pool. The only virtual thread which can 
release the connection to the pool is waiting for some platform threads to 
carry it. That is the platform thread is waiting for a connection while the 
connection is waiting the platform thread to carry its virtual thread and 
return the connection. Thus a deadlock.
   
    
   
   If we replace the synchronized above with a ReentrantLock, no thead will be 
pinned and no deadlock will occur. Accoring to the doc above, the limitation 
may be removed in future JDK versions. But before that, we may need to replace 
synchronized with some locks.  Do we have any related plan? Thanks!
   
   
   ---
   
   **Affects:** 4.4.16
   
   **Attachments:**
   - 
[LoomWithApacheHttpClientTest.java](https://issues.apache.org/jira/secure/attachment/13057955/LoomWithApacheHttpClientTest.java)
 (_2.54 kB_)
   
   0 votes, 6 watchers
   


-- 
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