Question

Il semble que Hibernate Search exécution synchrone utilise d'autres threads que le thread appelant à l'exécution en parallèle.

Comment puis-je exécuter les exécutions Hibernate Recherche en série dans le thread appelant?

Le problème semble être dans la classe 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 );
                }
            }
        }
    }

Une exécution synchrone série se passerait-il dans le thread appelant et exposerait des informations contextuelles telles que les informations d'authentification au DirectoryProvider sous-jacente.

Était-ce utile?

La solution

Très vieille question, mais je pourrais aussi bien répondre ...

Hibernate Search fait que, pour assurer l'accès monothread au IndexWriter Lucene pour un répertoire (qui est requis par Lucene). J'imagine l'utilisation d'un exécuteur monothread par répertoire était une façon de traiter le problème de mise en attente.

Si vous voulez tout à courir dans le thread appelant vous avez besoin de re-mettre en œuvre le LuceneBackendQueueProcessorFactory et le lier à hibernate.search.worker.backend dans les propriétés de mise en veille prolongée. Non trivial, mais faisables.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top