1
看起來,Hibernate Search同步執行使用除調用線程之外的其他線程來執行並行執行。Hibernate Search在主線程中執行同步執行
如何在調用線程中串行執行Hibernate Search執行?
這個問題似乎是在org.hibernate.search.backend.impl.lucene.QueueProcessors
類:
private void runAllWaiting() throws InterruptedException {
List<Future<Object>> futures = new ArrayList<Future<Object>>(dpProcessors.size());
// execute all work in parallel on each DirectoryProvider;
// each DP has it's own ExecutorService.
for (PerDPQueueProcessor process : dpProcessors.values()) {
ExecutorService executor = process.getOwningExecutor();
//wrap each Runnable in a Future
FutureTask<Object> f = new FutureTask<Object>(process, null);
futures.add(f);
executor.execute(f);
}
// and then wait for all tasks to be finished:
for (Future<Object> f : futures) {
if (!f.isDone()) {
try {
f.get();
}
catch (CancellationException ignore) {
// ignored, as in java.util.concurrent.AbstractExecutorService.invokeAll(Collection<Callable<T>>
// tasks)
}
catch (ExecutionException error) {
// rethrow cause to serviced thread - this could hide more exception:
Throwable cause = error.getCause();
throw new SearchException(cause);
}
}
}
}
串行同步執行將在調用線程發生,會暴露上下文信息,如身份驗證信息到底層DirectoryProvider。