lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject svn commit: r938646 - /lucene/dev/trunk/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java
Date Tue, 27 Apr 2010 20:58:02 GMT
Author: shaie
Date: Tue Apr 27 20:58:02 2010
New Revision: 938646

URL: http://svn.apache.org/viewvc?rev=938646&view=rev
Log:
LUCENE-2416: changed NORMALIZER (Pattern) to ThreadLocal, since it was left un-synced

Modified:
    lucene/dev/trunk/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java

Modified: lucene/dev/trunk/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java?rev=938646&r1=938645&r2=938646&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java
(original)
+++ lucene/dev/trunk/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/WriteLineDocTask.java
Tue Apr 27 20:58:02 2010
@@ -54,12 +54,12 @@ import org.apache.lucene.document.Field;
 public class WriteLineDocTask extends PerfTask {
 
   public final static char SEP = '\t';
-  private static final Matcher NORMALIZER = Pattern.compile("[\t\r\n]+").matcher("");
-
+  
   private int docSize = 0;
   private PrintWriter lineFileOut = null;
   private DocMaker docMaker;
   private ThreadLocal<StringBuilder> threadBuffer = new ThreadLocal<StringBuilder>();
+  private ThreadLocal<Matcher> threadNormalizer = new ThreadLocal<Matcher>();
   
   public WriteLineDocTask(PerfRunData runData) throws Exception {
     super(runData);
@@ -100,16 +100,22 @@ public class WriteLineDocTask extends Pe
   public int doLogic() throws Exception {
     Document doc = docSize > 0 ? docMaker.makeDocument(docSize) : docMaker.makeDocument();
 
+    Matcher matcher = threadNormalizer.get();
+    if (matcher == null) {
+      matcher = Pattern.compile("[\t\r\n]+").matcher("");
+      threadNormalizer.set(matcher);
+    }
+    
     Field f = doc.getField(DocMaker.BODY_FIELD);
-    String body = f != null ? NORMALIZER.reset(f.stringValue()).replaceAll(" ") : "";
+    String body = f != null ? matcher.reset(f.stringValue()).replaceAll(" ") : "";
     
     f = doc.getField(DocMaker.TITLE_FIELD);
-    String title = f != null ? NORMALIZER.reset(f.stringValue()).replaceAll(" ") : "";
+    String title = f != null ? matcher.reset(f.stringValue()).replaceAll(" ") : "";
     
     if (body.length() > 0 || title.length() > 0) {
       
       f = doc.getField(DocMaker.DATE_FIELD);
-      String date = f != null ? NORMALIZER.reset(f.stringValue()).replaceAll(" ") : "";
+      String date = f != null ? matcher.reset(f.stringValue()).replaceAll(" ") : "";
       
       StringBuilder sb = threadBuffer.get();
       if (sb == null) {



Mime
View raw message