Java中多线程间使用锁的简单记录
在写Lucene的应用时 因为同一个索引目录只能打开一个Writer,因此在打开之前需要同步
ReentrantLock reentrantLock=new ReentrantLock();
reentrantLock.lock();
writer = new IndexWriter(directory, iwConfig);
///do something 甘广欣
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
reentrantLock.unlock();