lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jianbao (Jim) Tao" <>
Subject Leftover write.lock file
Date Sun, 22 May 2016 17:20:07 GMT

I am new to lucene. I was following the example, IndexFiles, from the
lucene demo package. However, one thing I find surpring is that the
write.lock file is left over, even when the IndexWriter#close() method is
called. Below are details.

OS X Yosemite
java version "1.8.0_72"
Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)

lucene dependencies:

My Indexer and IndexerTest classes:
public class Indexer implements AutoCloseable {
    private IndexWriter writer;

    public Indexer(String indexDir) throws IOException {
        Directory dir =;
        Analyzer analyzer = new StandardAnalyzer();
        IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
        writer = new IndexWriter(dir, iwc);

    public void close() throws IOException {
        writer.close();"Indexer is successfully closed.");

    public int index(String docDir) throws IOException {
        File[] files = new File(docDir).listFiles();
        for (File f : files) {
            if (f.isDirectory() || f.isHidden()) continue;
        return writer.numDocs();

    private void indexFile(Path f) throws IOException {"Indexing {}", f);
        try (InputStream stream = Files.newInputStream(f)){
            Document doc = new Document();

            doc.add(new StringField("path", f.toString(), Field.Store.YES));
            doc.add(new LongPoint("modified",
            doc.add(new TextField("contents", new BufferedReader(new
InputStreamReader(stream, StandardCharsets.UTF_8))));
            writer.updateDocument(new Term("path", f.toString()), doc);

public class IndexerTest {
    public void testIndex() throws Exception {
        String indexDir = Shared.NOTES_INDEX_DIR; // Shared contains string
        try (Indexer indexer = new Indexer(indexDir)) {
            int indexedDocs = indexer.index(Shared.NOTES_DIR);
  "Indexed {} documents in {}", indexedDocs,
After running the testIndex() method, I can see this log:
    2016-05-22 09:50:17,532 INFO  [main] Indexer - Indexer is successfully
This indicates that the IndexWriter is successfully closed. However, I am
surprised to see that the write.lock still remains in the index directory.
I did a little digging. It appears that the `NativeFSLockFactory` is used
in my case. So, is it by design that the user is supposed to remove the
write.lock file manually when NativeFSLockFactory is used? I'd expect this
to be done automatically, but I guess there are probably important reasons
behind this behavior. In any case, I am just curious to know why.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message