You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "tang-hi (via GitHub)" <gi...@apache.org> on 2023/07/06 07:23:30 UTC

[GitHub] [lucene] tang-hi commented on issue #12419: IndexWriter and ConcurrentMergeScheduler and SegmentReader can cause static initialization deadlock

tang-hi commented on issue #12419:
URL: https://github.com/apache/lucene/issues/12419#issuecomment-1623127458

   In my opinion, this deadlock only occurs at the beginning of program execution. As long as you ensure that the IndexWriter is constructed before the ConcurrentMergeScheduler, the deadlock situation should not occur.
   
   Do you have a specific scenario where you need to concurrently construct the IndexWriter and ConcurrentMergeScheduler at the beginning of the program?
   ```Java
   public static void main(String[] args) throws Exception {
       CountDownLatch startLatch = new CountDownLatch(1);
   
       Thread t1 = new Thread(() -> {
         try {
           new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig());
         } catch (IOException e) {
           throw new RuntimeException(e);
         }
       });
   
       Thread t2 = new Thread(() -> {
         try {
           startLatch.await();
           new ConcurrentMergeScheduler();
         } catch (InterruptedException e) {
           throw new RuntimeException(e);
         }
       });
   
       t1.start();
       t2.start();
   
       t1.join();
       System.out.println("Start!");
       startLatch.countDown();
   
       t2.join();
   
       System.out.println("Done");
   
       for(int i = 0; i < 1000; i++) {
         deadlock();
       }
     }
   
     static void deadlock() throws InterruptedException {
       CountDownLatch startLatch = new CountDownLatch(1);
   
       Thread t1 = new Thread(() -> {
         try {
           startLatch.await();
           new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig());
         } catch (IOException | InterruptedException e) {
           throw new RuntimeException(e);
         }
       });
   
       Thread t2 = new Thread(() -> {
         try {
           startLatch.await();
           new ConcurrentMergeScheduler();
         } catch (InterruptedException e) {
           throw new RuntimeException(e);
         }
       });
   
       t1.start();
       t2.start();
   
       System.out.println("Start!");
       startLatch.countDown();
   
       t2.join();
       t1.join();
   
       System.out.println("Done");
     }
   
   ```


-- 
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-unsubscribe@lucene.apache.org

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


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