I have an application that crawls a site and writes the content as lucene index files into the physical directory.

When I use threads for this purpose, I am getting write errors or errors due to the locks.

I want to use multiple threads and write into the index files without missing the task of any of the threads.

```
public class WriteDocument
{
    private static Analyzer _analyzer;

    private static IndexWriter indexWriter;

    private static string Host;

    public WriteDocument(string _Host)
    {
        Host = _Host;
        Lucene.Net.Store.Directory _directory = FSDirectory.GetDirectory(Host, false);
        _analyzer = new StandardAnalyzer();
        bool indexExists = IndexReader.IndexExists(_directory);
        bool createIndex = !indexExists;

        indexWriter = new IndexWriter(_directory, _analyzer, true);
    }
    public void AddDocument(object obj)
    {
           DocumentSettings doc = (DocumentSettings)obj;               
           Field urlField = new Field("Url", doc.downloadedDocument.Uri.ToString(), Field.Store.YES, Field.Index.TOKENIZED);
            document.Add(urlField);
            indexWriter.AddDocument(document);

            document = null;
            doc.downloadedDocument = null;

            indexWriter.Optimize();
            indexWriter.Close();
      }
}

```

To the above class, I am passing the values like this:

```
DocumentSettings writedoc = new DocumentSettings()
{
      Host = Host,
      downloadedDocument = downloadDocument
};
Thread t = new Thread(() =>
{
doc.AddDocument(writedoc);
});
t.Start();

```

If I add `t.Join();` after `t.Start();` the code works for me without any errors. But this slows down my process and virtually, this is equal to the output I get without using threads.

I am getting error like: 

```
Cannot rename /indexes/Segments.new to /indexes/Segments 
the file is used by some other process.

```

Can anyone help me on this code?