[hibernate-commits] Hibernate SVN: r18939 - in search/trunk/src/main/java/org/hibernate/search: backend/impl/lucene and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Mar 9 05:48:54 EST 2010


Author: sannegrinovero
Date: 2010-03-09 05:48:53 -0500 (Tue, 09 Mar 2010)
New Revision: 18939

Modified:
   search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
   search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java
   search/trunk/src/main/java/org/hibernate/search/batchindexing/Executors.java
Log:
HSEARCH-421 - Exceptions happening in backend are unnoticed - First step: using a consistent Thread factory

Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java	2010-03-08 22:23:27 UTC (rev 18938)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java	2010-03-09 10:48:53 UTC (rev 18939)
@@ -28,8 +28,6 @@
 import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
 import org.slf4j.Logger;
@@ -49,6 +47,7 @@
 import org.hibernate.search.backend.impl.jgroups.SlaveJGroupsBackendQueueProcessorFactory;
 import org.hibernate.search.backend.impl.jms.JMSBackendQueueProcessorFactory;
 import org.hibernate.search.backend.impl.lucene.LuceneBackendQueueProcessorFactory;
+import org.hibernate.search.batchindexing.Executors;
 import org.hibernate.search.engine.DocumentBuilderIndexedEntity;
 import org.hibernate.search.engine.SearchFactoryImplementor;
 import org.hibernate.search.engine.DocumentBuilderContainedEntity;
@@ -76,7 +75,7 @@
 		this.sync = isConfiguredAsSync( properties );
 
 		//default to a simple asynchronous operation
-		int min = ConfigurationParseHelper.getIntValue( properties, Environment.WORKER_THREADPOOL_SIZE, 1 );
+		int threadPoolSize = ConfigurationParseHelper.getIntValue( properties, Environment.WORKER_THREADPOOL_SIZE, 1 );
 		//no queue limit
 		int queueSize = ConfigurationParseHelper.getIntValue(
 				properties, Environment.WORKER_WORKQUEUE_SIZE, Integer.MAX_VALUE
@@ -86,17 +85,9 @@
 
 		if ( !sync ) {
 			/**
-			 * choose min = max with a sizable queue to be able to
-			 * actually queue operations
-			 * The locking mechanism preventing much of the scalability
-			 * anyway, the idea is really to have a buffer
 			 * If the queue limit is reached, the operation is executed by the main thread
 			 */
-			executorService = new ThreadPoolExecutor(
-					min, min, 60, TimeUnit.SECONDS,
-					new LinkedBlockingQueue<Runnable>( queueSize ),
-					new ThreadPoolExecutor.CallerRunsPolicy()
-			);
+			executorService =  Executors.newFixedThreadPool( threadPoolSize, "backend queueing processor", queueSize );
 		}
 		else {
 			executorService = null;

Modified: search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java	2010-03-08 22:23:27 UTC (rev 18938)
+++ search/trunk/src/main/java/org/hibernate/search/backend/impl/lucene/PerDPResources.java	2010-03-09 10:48:53 UTC (rev 18939)
@@ -24,14 +24,14 @@
  */
 package org.hibernate.search.backend.impl.lucene;
 
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
 import org.hibernate.search.backend.Workspace;
 import org.hibernate.search.backend.impl.lucene.works.LuceneWorkVisitor;
+import org.hibernate.search.batchindexing.Executors;
 import org.hibernate.search.engine.SearchFactoryImplementor;
 import org.hibernate.search.store.DirectoryProvider;
 
+import java.util.concurrent.ExecutorService;
+
 /**
  * Collects all resources needed to apply changes to one index,
  * and are reused across several WorkQueues.
@@ -48,7 +48,7 @@
 	PerDPResources(SearchFactoryImplementor searchFactoryImp, DirectoryProvider<?> dp) {
 		workspace = new Workspace( searchFactoryImp, dp );
 		visitor = new LuceneWorkVisitor( workspace );
-		executor = Executors.newFixedThreadPool( 1 );
+		executor = Executors.newFixedThreadPool( 1, "Directory writer" );
 		exclusiveIndexUsage = searchFactoryImp.isExclusiveIndexUsageEnabled( dp );
 	}
 

Modified: search/trunk/src/main/java/org/hibernate/search/batchindexing/Executors.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/batchindexing/Executors.java	2010-03-08 22:23:27 UTC (rev 18938)
+++ search/trunk/src/main/java/org/hibernate/search/batchindexing/Executors.java	2010-03-09 10:48:53 UTC (rev 18939)
@@ -53,11 +53,22 @@
 	 * @return the new ExecutorService
 	 */
 	public static ThreadPoolExecutor newFixedThreadPool(int threads, String groupname) {
+		return newFixedThreadPool( threads, groupname, QUEUE_MAX_LENGTH );
+	}
+
+    /**
+     * Creates a new fixed size ThreadPoolExecutor
+     * @param threads the number of threads
+     * @param groupname a label to identify the threadpool; useful for profiling.
+     * @param queueSize the size of the queue to store Runnables when all threads are busy
+     * @return the new ExecutorService
+     */
+	public static ThreadPoolExecutor newFixedThreadPool(int threads, String groupname, int queueSize) {
 		return new ThreadPoolExecutor(
 				threads,
 				threads,
 	            0L, TimeUnit.MILLISECONDS,
-	            new LinkedBlockingQueue<Runnable>( QUEUE_MAX_LENGTH ),
+	            new LinkedBlockingQueue<Runnable>( queueSize ),
 	            new SearchThreadFactory( groupname ),
 	            new ThreadPoolExecutor.CallerRunsPolicy() );
 	}



More information about the hibernate-commits mailing list