uschindler commented on code in PR #12199:
URL: https://github.com/apache/lucene/pull/12199#discussion_r1133708757


##########
lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThreadPool.java:
##########
@@ -113,15 +113,17 @@ private synchronized DocumentsWriterPerThread newWriter() 
{
    * operation (add/updateDocument).
    */
   DocumentsWriterPerThread getAndLock() {
-    synchronized (this) {
-      ensureOpen();
-      DocumentsWriterPerThread dwpt = 
freeList.poll(DocumentsWriterPerThread::tryLock);
-      if (dwpt == null) {
-        dwpt = newWriter();
-      }
-      // DWPT is already locked before return by this method:
-      return dwpt;
+    ensureOpen();
+    DocumentsWriterPerThread dwpt = 
freeList.poll(DocumentsWriterPerThread::tryLock);
+    if (dwpt == null) {
+      // newWriter() adds the DWPT to the `dwpts` set as a side-effect. 
However it is not added to
+      // `freeList` at this point, it will be added later on once 
DocumentsWriter has indexed a
+      // document into this DWPT and then gives it back to the pool by calling
+      // #marksAsFreeAndUnlock.
+      dwpt = newWriter();

Review Comment:
   Don't need to do this, but looks much more "Java 17 like" - just for 
demonstation purposes:
   ```java
   return 
Optional.ofNullable(freeList.poll(DocumentsWriterPerThread::tryLock)).orElseGet(this::newWriter);
   ```



-- 
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: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to