title: org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
body: <p>I am trying to index a large set of log files obtained from a tomcat server. I have written the code to open each file, create an index for each line and then store each line using Apache lucene. All of this is done using multi-threading.</p>
  
  <p>I get the this exception when i try to this code</p>
  
  <pre><code>org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
  </code></pre>
  
  <p>Code</p>
  
  <pre><code>  if (indexWriter.getConfig().getOpenMode() == IndexWriterConfig.OpenMode.CREATE)
          {
            // New index, so we just add the document (no old document can be there):
             System.out.println("adding " + path);
  
                  indexWriter.addDocument(doc);
  
         } else {
            // Existing index (an old copy of this document may have been indexed) so 
         // we use updateDocument instead to replace the old one matching the exact 
             // path, if present:
              System.out.println("updating " + path);
  
                  indexWriter.updateDocument(new Term("path", path), doc);
  
            }
          indexWriter.commit();
          indexWriter.close();
  </code></pre>
  
  <p>Now I thought since i am committing the index every time, it might cause a write lock. so i removed <code>indexWriter.commit();</code>:</p>
  
  <pre><code>if (indexWriter.getConfig().getOpenMode() == IndexWriterConfig.OpenMode.CREATE)
      {
        // New index, so we just add the document (no old document can be there):
         System.out.println("adding " + path);
  
              indexWriter.addDocument(doc);
  
     } else {
        // Existing index (an old copy of this document may have been indexed) so 
     // we use updateDocument instead to replace the old one matching the exact 
         // path, if present:
          System.out.println("updating " + path);
  
              indexWriter.updateDocument(new Term("path", path), doc);
  
        }
  
      indexWriter.close();
  </code></pre>
  
  <p>Now i get no exception</p>
  
  <p><strong>Q. So my question is why indexWriter.commit(); causes the exception. And even if I remove indexWriter.commit(); i do not get any problem while searching. That is I get the exact result I intended to have. Then why to use indexWriter.commit(); ?</strong></p>