FileDocCategorySizeDatePackage
TestMultiThreadTermVectors.javaAPI DocApache Lucene 2.1.05487Wed Feb 14 10:46:36 GMT 2007org.apache.lucene.search

TestMultiThreadTermVectors

public class TestMultiThreadTermVectors extends TestCase
author
Bernhard Messer
version
$rcs = ' $Id: TestMultiThreadTermVectors.java 487922 2006-12-17 00:10:40Z otis $ ' ;

Fields Summary
private RAMDirectory
directory
public int
numDocs
public int
numThreads
Constructors Summary
public TestMultiThreadTermVectors(String s)

  
     
    super(s);
  
Methods Summary
public voidsetUp()

    IndexWriter writer
            = new IndexWriter(directory, new SimpleAnalyzer(), true);
    //writer.setUseCompoundFile(false);
    //writer.infoStream = System.out;
    for (int i = 0; i < numDocs; i++) {
      Document doc = new Document();
      Fieldable fld = new Field("field", English.intToEnglish(i), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.YES);
      doc.add(fld);
      writer.addDocument(doc);
    }
    writer.close();
    
  
public voidtest()

    
    IndexReader reader = null;
    
    try {
      reader = IndexReader.open(directory);
      for(int i = 1; i <= numThreads; i++)
        testTermPositionVectors(reader, i);
      
      
    }
    catch (IOException ioe) {
      fail(ioe.getMessage());
    }
    finally {
      if (reader != null) {
        try {
          /** close the opened reader */
          reader.close();
        } catch (IOException ioe) {
          ioe.printStackTrace();
        }
      }
    }
  
public voidtestTermPositionVectors(org.apache.lucene.index.IndexReader reader, int threadCount)

    MultiThreadTermVectorsReader[] mtr = new MultiThreadTermVectorsReader[threadCount];
    for (int i = 0; i < threadCount; i++) {
      mtr[i] = new MultiThreadTermVectorsReader();
      mtr[i].init(reader);
    }
    
    
    /** run until all threads finished */ 
    int threadsAlive = mtr.length;
    while (threadsAlive > 0) {
      try {
        //System.out.println("Threads alive");
        Thread.sleep(10);
        threadsAlive = mtr.length;
        for (int i = 0; i < mtr.length; i++) {
          if (mtr[i].isAlive() == true) {
            break;
          }
          
          threadsAlive--; 
          
      }
        
      } catch (InterruptedException ie) {} 
    }
    
    long totalTime = 0L;
    for (int i = 0; i < mtr.length; i++) {
      totalTime += mtr[i].timeElapsed;
      mtr[i] = null;
    }
    
    //System.out.println("threadcount: " + mtr.length + " average term vector time: " + totalTime/mtr.length);