`
Rexwong
  • 浏览: 10524 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Lucene————DocumentsWriter--getThreadState()

阅读更多
/**
	 * Returns a free (idle) ThreadState that may be used for indexing this one
	 * document. This call also pauses if a flush is pending. If delTerm is
	 * non-null then we buffer this deleted term after the thread state has been
	 * acquired. 返回一个空闲的ThreadState,它用于索引的当前document。当刷新正在等待时,调用将会暂停
	 */
	synchronized DocumentsWriterThreadState getThreadState(Document doc,
			Term delTerm) throws IOException {

		// First, find a thread state. If this thread already
		// has affinity to a specific ThreadState, use that one
		// again.
		/** 通过HashMap将DocumentsWriterThreadState绑定本地线程,用于多线程的支持 */
		DocumentsWriterThreadState state = threadBindings.get(Thread
				.currentThread());
		if (state == null) {

			// First time this thread has called us since last
			// flush. Find the least loaded thread state:
			/** ts.numThreads,numThreads是分享当前实例的线程数 */
			DocumentsWriterThreadState minThreadState = null;
			for (int i = 0; i < threadStates.length; i++) {
				DocumentsWriterThreadState ts = threadStates[i];
				/**
				 * 得到threadStates数组中一个线程数最少的DocumentsWriterThreadState
				 * 第一次添加docment时threadStates数组是null
				 **/
				if (minThreadState == null
						|| ts.numThreads < minThreadState.numThreads)
					minThreadState = ts;
			}
			if (minThreadState != null
					&& (minThreadState.numThreads == 0 || threadStates.length >= MAX_THREAD_STATE)) {
				state = minThreadState;
				state.numThreads++;
			} else {
				// Just create a new "private" thread state(创建一个“私有”thread
				// state)
				/**
				 * 当threadStates是null时,调用此处。
				 * threadStates是一个DocumentsWriterThreadState数组。
				 */
				DocumentsWriterThreadState[] newArray = new DocumentsWriterThreadState[1 + threadStates.length];
				if (threadStates.length > 0)
					System.arraycopy(threadStates, 0, newArray, 0,
							threadStates.length);
				state = newArray[threadStates.length] = new DocumentsWriterThreadState(
						this);
				threadStates = newArray;
			}

			threadBindings.put(Thread.currentThread(), state);
		}

		// Next, wait until my thread state is idle (in case
		// it's shared with other threads) and for threads to
		// not be paused nor a flush pending:
		/** 等到state空闲 ,暂停程序 */
		waitReady(state);

		// Allocate segment name if this is the first doc since
		// last flush:
		initSegmentName(false);

		state.isIdle = false;

		boolean success = false;
		try {
			state.docState.docID = nextDocID;

			assert writer.testPoint("DocumentsWriter.ThreadState.init start");

			if (delTerm != null) {
				addDeleteTerm(delTerm, state.docState.docID);
				state.doFlushAfter = timeToFlushDeletes();
			}

			assert writer
					.testPoint("DocumentsWriter.ThreadState.init after delTerm");
			/** 反复添加document时docid的增加,所以不同的docid对应相应的document */
			nextDocID++;
			numDocsInRAM++;// numDocsInRAM---docs buffered in RAM

			// We must at this point commit to flushing to ensure we
			// always get N docs when we flush by doc count, even if
			// > 1 thread is adding documents:
			if (!flushPending
					&& maxBufferedDocs != IndexWriter.DISABLE_AUTO_FLUSH
					&& numDocsInRAM >= maxBufferedDocs) {
				flushPending = true;
				state.doFlushAfter = true;
			}

			success = true;
		} finally {
			if (!success) {
				// Forcefully idle this ThreadState:
				state.isIdle = true;
				notifyAll();
				if (state.doFlushAfter) {
					state.doFlushAfter = false;
					flushPending = false;
				}
			}
		}

		return state;
	}

 

分享到:
评论

相关推荐

    lucene-spatial3d-6.6.0-API文档-中文版.zip

    赠送jar包:lucene-spatial3d-6.6.0.jar; 赠送原API文档:lucene-spatial3d-6.6.0-javadoc.jar; 赠送源代码:lucene-spatial3d-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial3d-6.6.0.pom; 包含...

    lucene-spatial3d-7.3.1-API文档-中英对照版.zip

    赠送jar包:lucene-spatial3d-7.3.1.jar; 赠送原API文档:lucene-spatial3d-7.3.1-javadoc.jar; 赠送源代码:lucene-spatial3d-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial3d-7.3.1.pom; 包含...

    lucene-spatial3d-7.2.1-API文档-中文版.zip

    赠送jar包:lucene-spatial3d-7.2.1.jar; 赠送原API文档:lucene-spatial3d-7.2.1-javadoc.jar; 赠送源代码:lucene-spatial3d-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial3d-7.2.1.pom; 包含...

    lucene-spatial3d-6.6.0-API文档-中英对照版.zip

    赠送jar包:lucene-spatial3d-6.6.0.jar; 赠送原API文档:lucene-spatial3d-6.6.0-javadoc.jar; 赠送源代码:lucene-spatial3d-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial3d-6.6.0.pom; 包含...

    lucene-spatial3d-7.7.0-API文档-中文版.zip

    赠送jar包:lucene-spatial3d-7.7.0.jar; 赠送原API文档:lucene-spatial3d-7.7.0-javadoc.jar; 赠送源代码:lucene-spatial3d-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial3d-7.7.0.pom; 包含...

    lucene-spatial3d-7.3.1-API文档-中文版.zip

    赠送jar包:lucene-spatial3d-7.3.1.jar; 赠送原API文档:lucene-spatial3d-7.3.1-javadoc.jar; 赠送源代码:lucene-spatial3d-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial3d-7.3.1.pom; 包含...

    lucene-core-7.7.0-API文档-中文版.zip

    赠送jar包:lucene-core-7.7.0.jar; 赠送原API文档:lucene-core-7.7.0-javadoc.jar; 赠送源代码:lucene-core-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-core-7.7.0.pom; 包含翻译后的API文档:lucene...

    lucene-spatial3d-7.7.0-API文档-中英对照版.zip

    赠送jar包:lucene-spatial3d-7.7.0.jar; 赠送原API文档:lucene-spatial3d-7.7.0-javadoc.jar; 赠送源代码:lucene-spatial3d-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial3d-7.7.0.pom; 包含...

    lucene-spatial3d-7.2.1-API文档-中英对照版.zip

    赠送jar包:lucene-spatial3d-7.2.1.jar; 赠送原API文档:lucene-spatial3d-7.2.1-javadoc.jar; 赠送源代码:lucene-spatial3d-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial3d-7.2.1.pom; 包含...

    lucene-analyzers-smartcn-7.7.0-API文档-中文版.zip

    赠送jar包:lucene-analyzers-smartcn-7.7.0.jar; 赠送原API文档:lucene-analyzers-smartcn-7.7.0-javadoc.jar; 赠送源代码:lucene-analyzers-smartcn-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-...

    Lucene中文分词组件 JE-Analysis 1.5.1

    全面支持Lucene 2.0 增强了词典维护的API 增加了商品编码的匹配 增加了Mail地址的匹配 实现了词尾消歧算法第二层的过滤 整理优化了词库 1.4.0 —— 2006-08-21 增加词典的动态扩展能力 1.3.3 ...

    全文检索技术学习(三)——Lucene支持中文分词 - 李阿昀的博客 - CSDN博客1

    在全文检索技术中,Lucene 是一个非常重要的开源搜索引擎库,它提供了强大的文本分析和索引功能。在处理中文文本时,由于中文的特殊性,需要进行分词处理才能有效地进行搜索。本篇博客主要讨论了如何使用 Lucene ...

    lucene-highlighter-6.6.0-API文档-中文版.zip

    赠送jar包:lucene-highlighter-6.6.0.jar; 赠送原API文档:lucene-highlighter-6.6.0-javadoc.jar; 赠送源代码:lucene-highlighter-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-highlighter-6.6.0.pom;...

    lucene-analyzers-common-6.6.0-API文档-中文版.zip

    赠送jar包:lucene-analyzers-common-6.6.0.jar; 赠送原API文档:lucene-analyzers-common-6.6.0-javadoc.jar; 赠送源代码:lucene-analyzers-common-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-...

    【大搜集:lucene学习资料】---<下载不扣分,回帖加1分,欢迎下载,童叟无欺>

    基于Java的全文索引引擎.doc ... Lucene-2.0学习文档 .txt Lucene入门与使用 .txt lucene性能.txt 大富翁全文索引和查询的例子程序.txt 关于lucene2.0的创建、检索和删除功能的完整实现.doc weblucene.txt

    lucene-backward-codecs-7.3.1-API文档-中英对照版.zip

    赠送jar包:lucene-backward-codecs-7.3.1.jar; 赠送原API文档:lucene-backward-codecs-7.3.1-javadoc.jar; 赠送源代码:lucene-backward-codecs-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-backward-...

    lucene-analyzers-smartcn-7.7.0-API文档-中英对照版.zip

    赠送jar包:lucene-analyzers-smartcn-7.7.0.jar; 赠送原API文档:lucene-analyzers-smartcn-7.7.0-javadoc.jar; 赠送源代码:lucene-analyzers-smartcn-7.7.0-sources.jar; 赠送Maven依赖信息文件:lucene-...

    lucene-spatial-extras-7.3.1-API文档-中英对照版.zip

    赠送jar包:lucene-spatial-extras-7.3.1.jar; 赠送原API文档:lucene-spatial-extras-7.3.1-javadoc.jar; 赠送源代码:lucene-spatial-extras-7.3.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...

    lucene-spatial-extras-7.2.1-API文档-中英对照版.zip

    赠送jar包:lucene-spatial-extras-7.2.1.jar; 赠送原API文档:lucene-spatial-extras-7.2.1-javadoc.jar; 赠送源代码:lucene-spatial-extras-7.2.1-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...

    lucene-spatial-extras-6.6.0-API文档-中英对照版.zip

    赠送jar包:lucene-spatial-extras-6.6.0.jar; 赠送原API文档:lucene-spatial-extras-6.6.0-javadoc.jar; 赠送源代码:lucene-spatial-extras-6.6.0-sources.jar; 赠送Maven依赖信息文件:lucene-spatial-extras...

Global site tag (gtag.js) - Google Analytics