深入浅出 jackrabbit 四 索引提交(上)
2009-09-17 00:00:00 来源:WEB开发网Java代码
void addDocuments(Document[] docs) throws IOException {
final IndexWriter writer = getIndexWriter();
//一般情况下,我们的docs数组的长度为10,下面就创建10个线程
DynamicPooledExecutor.Command commands[] =
new DynamicPooledExecutor.Command[docs.length];
for (int i = 0; i < docs.length; i++) {
// check if text extractor completed its work
final Document doc = getFinishedDocument(docs[i]);
// create a command for inverting the document
commands[i] = new DynamicPooledExecutor.Command() {
public Object call() throws Exception {
long time = System.currentTimeMillis();
//每个线程都使用往writer里加入document对象,这个时候,lucene开始解析document,并生产index数据
writer.addDocument(doc);
return new Long(System.currentTimeMillis() - time);
}
};
}
//并发执行
DynamicPooledExecutor.Result results[] = EXECUTOR.executeAndWait(commands);
//置空readOnlyReader和sharedReader,为啥置空啊,index数据改了呗
invalidateSharedReader();
IOException ex = null;
//检查每个线程的执行情况,有一个出错就抛出异常,其他的异常保存到log中
for (int i = 0; i < results.length; i++) {
if (results[i].getException() != null) {
Throwable cause = results[i].getException().getCause();
if (ex == null) {
// only throw the first exception
if (cause instanceof IOException) {
ex = (IOException) cause;
} else {
IOException e = new IOException();
e.initCause(cause);
ex = e;
}
} else {
// all others are logged
log.warn("Exception while inverting document", cause);
}
} else {
log.debug("Inverted document in {} ms", results[i].get());
}
}
if (ex != null) {
throw ex;
}
}
Tags:深入浅出 jackrabbit 索引
编辑录入:爽爽 [复制链接] [打 印]- ››深入浅出实战攻防恶意PDF文档
- ››深入浅出ShellExecute
- ››深入浅出URL编码
- ››深入浅出Java多线程程序设计
- ››深入浅出 jackrabbit 八 索引合并(上)
- ››深入浅出 jackrabbit 九 索引合并(下)
- ››深入浅出 jackrabbit 十 redolog 和 recovery.doc...
- ››深入浅出 jackrabbit 十一 jackrabbit改进要点
- ››深入浅出 jackrabbit 十二 key-value存储系统
- ››深入浅出 jackrabbit 十三 查询之AST和QT
- ››深入浅出 jackrabbit 一
- ››深入浅出 jackrabbit 二 索引概览
更多精彩
赞助商链接