Lock obtain timed out: simplefslock @ E: // cause of javasource // deleetest // index // write. Lock exception:
1. When Lucene writes an index, it is used to create a write under the index directory. lock file to identify the lock. the lock file will be deleted only after the close () method is executed. if this file exists, other indexedProgramAn error is reported:
Caught a class org. Apache. Lucene. Store. lockobtainfailedexception
With message: Lock obtain timed out: simplefslock @ E: // your ource // your Etest // index // write. Lock
Therefore, be sure to disable indexwrite. If an exception occurs, use finally to disable it. Otherwise, the next index write will fail.
2. If the Lucene index directory contains a lot of files, it is definitely a problem. several aspects. when Lucene performs a write operation, it first writes a Write statement in the directory. lock file to lock this directory, to avoid other indexes and then operate on this path. otherwise, it will be messy. after the lock, start to write the index. When writing the index, Lucene creates several or dozens of temporary fragment files, which all seem to be short and messy characters. CFS file. after the index is created, no indexwriter is executed. optimize (); method, it will not merge those messy files. therefore, after the index is created, you must execute the above optimization method to keep three files in the directory. that is, many temporary files will be merged into one file. you cannot delete it. however, when there is a large amount of data, we will consider other strategies.
3. Add indexes in batches. What should I do if I want to add indexes cyclically in batches? First, please note: indexwriter = new indexwriter (indexdir,
New thesaurusanalyzer (), false); the last parameter "false" indicates that data is continuously added to the index. If it is set to true, all data is deleted and restarted each time.
4. When adding indexes in batches, the program can always Execute
Indexwriter. adddocument (DOC); but cannot be optimized all the time: indexwriter. optimize (); because the optimization method is time-consuming, especially when the index is large, pay attention to it. because of the optimization, it just seems that the optimization will consume a lot of time and CPU. so this time. it does not matter if there are several more files.