FileDocCategorySizeDatePackage
TestMultiThreadTermVectors.javaAPI DocApache Lucene 1.95027Mon Feb 20 09:19:32 GMT 2006org.apache.lucene.search

TestMultiThreadTermVectors

public class TestMultiThreadTermVectors extends TestCase
author
Bernhard Messer
version
$rcs = ' $Id: TestMultiThreadTermVectors.java 150569 2004-10-06 10:40:23Z goller $ ' ;

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();
    	Field 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);