當前位置: 首頁>>代碼示例>>Java>>正文


Java SlowRAMDirectory.setSleepMillis方法代碼示例

本文整理匯總了Java中org.apache.lucene.facet.SlowRAMDirectory.setSleepMillis方法的典型用法代碼示例。如果您正苦於以下問題:Java SlowRAMDirectory.setSleepMillis方法的具體用法?Java SlowRAMDirectory.setSleepMillis怎麽用?Java SlowRAMDirectory.setSleepMillis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.facet.SlowRAMDirectory的用法示例。


在下文中一共展示了SlowRAMDirectory.setSleepMillis方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testMemoryCacheSynchronization

import org.apache.lucene.facet.SlowRAMDirectory; //導入方法依賴的package包/類
/**
 * Test that a new TFC is only calculated and placed in memory (by two
 * threads who want it at the same time) only once.
 */
@Test
public void testMemoryCacheSynchronization() throws Exception {
  SlowRAMDirectory indexDir = new SlowRAMDirectory(-1, null);
  SlowRAMDirectory taxoDir = new SlowRAMDirectory(-1, null);

  // Write index using 'normal' directories
  IndexWriter w = new IndexWriter(indexDir, new IndexWriterConfig(
      TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)));
  DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
  FacetIndexingParams iParams = FacetIndexingParams.DEFAULT;
  // Add documents and facets
  for (int i = 0; i < 1000; i++) {
    addFacets(iParams, w, tw, "facet", Integer.toString(i));
  }
  w.close();
  tw.close();

  indexDir.setSleepMillis(1);
  taxoDir.setSleepMillis(1);

  IndexReader r = DirectoryReader.open(indexDir);
  DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);

  // Create and start threads. Thread1 should lock the cache and calculate
  // the TFC array. The second thread should block until the first is
  // done, then successfully retrieve from the cache without recalculating
  // or reading from disk.
  TFCThread tfcCalc1 = new TFCThread(r, tr, iParams);
  TFCThread tfcCalc2 = new TFCThread(r, tr, iParams);
  tfcCalc1.start();
  // Give thread 1 a head start to ensure correct sequencing for testing
  Thread.sleep(5);
  tfcCalc2.start();

  tfcCalc1.join();
  tfcCalc2.join();

  // Since this test ends up with references to the same TFC object, we
  // can only test the times to make sure that they are the same.
  assertRecomputed(tfcCalc1.tfc, 0, "thread 1 should recompute");
  assertRecomputed(tfcCalc2.tfc, 0, "thread 2 should recompute");
  assertTrue("Both results should be the same (as their inputs are the same objects)",
      tfcCalc1.tfc == tfcCalc2.tfc);

  r.close();
  tr.close();
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:52,代碼來源:TestTotalFacetCountsCache.java


注:本文中的org.apache.lucene.facet.SlowRAMDirectory.setSleepMillis方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。