lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r609080 - in /lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds: EnwikiDocMaker.java LineDocMaker.java
Date Sat, 05 Jan 2008 01:51:54 GMT
Author: mikemccand
Date: Fri Jan  4 17:51:53 2008
New Revision: 609080

URL: http://svn.apache.org/viewvc?rev=609080&view=rev
Log:
LUCENE-1117: fix intermittent thread safety issue w/ EnwikiDocMaker

Modified:
    lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiDocMaker.java
    lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LineDocMaker.java

Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiDocMaker.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiDocMaker.java?rev=609080&r1=609079&r2=609080&view=diff
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiDocMaker.java
(original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiDocMaker.java
Fri Jan  4 17:51:53 2008
@@ -25,6 +25,7 @@
 import org.xml.sax.helpers.XMLReaderFactory;
 
 import java.io.IOException;
+import java.io.FileInputStream;
 
 import org.apache.lucene.document.Document;
 
@@ -55,16 +56,28 @@
         reader.setContentHandler(this);
         reader.setErrorHandler(this);
         while(true){
-          InputSource is = new InputSource(fileIS);
-          reader.parse(is);
-          if (!forever) {
-            synchronized(this) {
+          final FileInputStream localFileIS = fileIS;
+          try {
+            InputSource is = new InputSource(localFileIS);
+            reader.parse(is);
+          } catch (IOException ioe) {
+            synchronized(EnwikiDocMaker.this) {
+              if (localFileIS != fileIS) {
+                // fileIS was closed on us, so, just fall
+                // through
+              } else
+                // Exception is real
+                throw ioe;
+            }
+          }
+          synchronized(this) {
+            if (!forever) {
               nmde = new NoMoreDataException();
               notify();
-            }
-            return;
-          } else {
-            synchronized(this){
+              return;
+            } else if (localFileIS == fileIS) {
+              // If file is not already re-opened then
+              // re-open it now
               openFile();
             }
           }
@@ -77,16 +90,15 @@
 
     }
 
-    Parser() {
-      t = new Thread(this);
-      t.setDaemon(true);
-      t.start();
-    }
-
     String[] tuple;
     NoMoreDataException nmde;
 
     String[] next() throws NoMoreDataException {
+      if (t == null) {
+        t = new Thread(this);
+        t.setDaemon(true);
+        t.start();
+      }
       String[] result;
       synchronized(this){
         while(tuple == null && nmde == null){
@@ -96,6 +108,9 @@
           }
         }
         if (nmde != null) {
+          // Set to null so we will re-start thread in case
+          // we are re-used:
+          t = null;
           throw nmde;
         }
         result = tuple;

Modified: lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LineDocMaker.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LineDocMaker.java?rev=609080&r1=609079&r2=609080&view=diff
==============================================================================
--- lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LineDocMaker.java
(original)
+++ lucene/java/trunk/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LineDocMaker.java
Fri Jan  4 17:51:53 2008
@@ -101,14 +101,6 @@
     }
   }
 
-  /* (non-Javadoc)
-   * @see SimpleDocMaker#setConfig(java.util.Properties)
-   */
-  public void setConfig(Config config) {
-    super.setConfig(config);
-    resetInputs();
-  }
-
   protected DocData getNextDocData() throws Exception {
     throw new RuntimeException("not implemented");
   }
@@ -154,7 +146,7 @@
     openFile();
   }
 
-  void openFile() {
+  synchronized void openFile() {
     try {
       if (fileIn != null)
         fileIn.close();



Mime
View raw message