madrob commented on a change in pull request #1358: SOLR-14256: replaced EMPTY 
with empty() to fix deadlock
URL: https://github.com/apache/lucene-solr/pull/1358#discussion_r394061330
 
 

 ##########
 File path: solr/core/src/java/org/apache/solr/search/DocSet.java
 ##########
 @@ -36,6 +36,21 @@
     assert this instanceof BitDocSet || this instanceof SortedIntDocSet;
   }
 
+  // we can't simply use a trivial static initializer "= new SortedIntDocSet" 
because it can lead to classloader deadlock
+  private static DocSet EMPTY;
+
+  /** An empty instance. */
+  public static DocSet empty() {
 
 Review comment:
   I'll refer to the much wiser than myself, Josh Bloch (emphasis mine) -
   
   > In summary, you should initialize most fields normally, not lazily. If you 
must initialize a field lazily in order to... break a harmful initialization 
circularity, then use the appropriate lazy initialization technique. For 
instance fields, it is the double-check idiom; **for static fields, the lazy 
initialization holder class idiom**. For instance fields that can tolerate 
repeated initialization, you may also consider the single-check idiom.
   
   There's actually a lot more nuance in the surrounding paragraphs in the 
book, most of which I don't understand, but the summary appears to suggest that 
this is the fastest, simplest way.
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to