Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2009-04-24 22:36:15 +0000
committerChris Goldthorpe2009-04-24 22:36:15 +0000
commit60a84efe77a44cdb9ceda15cf8f0eb6d9147512c (patch)
treec982f59e86c5b0fe09e4a0e116d0ef5ff7826a8a /org.eclipse.help.base/src_demo/org/apache/lucene/demo/html
parentee2eac16cd0c66b257834efcb1e268fbb362d89a (diff)
downloadeclipse.platform.ua-60a84efe77a44cdb9ceda15cf8f0eb6d9147512c.tar.gz
eclipse.platform.ua-60a84efe77a44cdb9ceda15cf8f0eb6d9147512c.tar.xz
eclipse.platform.ua-60a84efe77a44cdb9ceda15cf8f0eb6d9147512c.zip
Bug 186681 – [Help] Too many threads created for indexingv20090502v20090428v20090424_1600
Diffstat (limited to 'org.eclipse.help.base/src_demo/org/apache/lucene/demo/html')
-rw-r--r--org.eclipse.help.base/src_demo/org/apache/lucene/demo/html/HTMLParser.java79
-rw-r--r--org.eclipse.help.base/src_demo/org/apache/lucene/demo/html/ParserThread.java54
2 files changed, 19 insertions, 114 deletions
diff --git a/org.eclipse.help.base/src_demo/org/apache/lucene/demo/html/HTMLParser.java b/org.eclipse.help.base/src_demo/org/apache/lucene/demo/html/HTMLParser.java
index 7d65fc835..ddbeeee56 100644
--- a/org.eclipse.help.base/src_demo/org/apache/lucene/demo/html/HTMLParser.java
+++ b/org.eclipse.help.base/src_demo/org/apache/lucene/demo/html/HTMLParser.java
@@ -33,6 +33,8 @@ package org.apache.lucene.demo.html;
import java.io.*;
import java.util.Properties;
+import org.eclipse.help.internal.search.LimitedSizeCharArrayWriter;
+
public class HTMLParser implements HTMLParserConstants {
public static int SUMMARY_LENGTH = 175;
@@ -50,23 +52,9 @@ public class HTMLParser implements HTMLParserConstants {
boolean afterTag = false;
boolean afterSpace = false;
String eol = System.getProperty("line.separator"); //$NON-NLS-1$
- Reader pipeIn = null;
- Writer pipeOut;
- private MyPipedInputStream pipeInStream = null;
- private PipedOutputStream pipeOutStream = null;
+ private LimitedSizeCharArrayWriter writer = new LimitedSizeCharArrayWriter(1000000);
private Exception exception = null;
- private class MyPipedInputStream extends PipedInputStream{
-
- public MyPipedInputStream(){
- super();
- }
-
- public boolean full() throws IOException{
- return this.available() >= PipedInputStream.PIPE_SIZE;
- }
- }
-
/**
* @deprecated Use HTMLParser(FileInputStream) instead
*/
@@ -74,44 +62,17 @@ public class HTMLParser implements HTMLParserConstants {
this(new FileInputStream(file));
}
- public String getTitle() throws IOException, InterruptedException {
- if (pipeIn == null)
- getReader(); // spawn parsing thread
- while (true) {
- synchronized(this) {
- if (titleComplete || pipeInStream.full())
- break;
- wait(10);
- }
- }
+ public String getTitle() throws IOException, InterruptedException { // spawn parsing thread
return title.toString().trim();
}
public Properties getMetaTags() throws IOException,
InterruptedException {
- if (pipeIn == null)
- getReader(); // spawn parsing thread
- while (true) {
- synchronized(this) {
- if (titleComplete || pipeInStream.full())
- break;
- wait(10);
- }
- }
return metaTags;
}
- public String getSummary() throws IOException, InterruptedException {
- if (pipeIn == null)
- getReader(); // spawn parsing thread
- while (true) {
- synchronized(this) {
- if (summary.length() >= SUMMARY_LENGTH || pipeInStream.full())
- break;
- wait(10);
- }
- }
+ public String getSummary() throws IOException, InterruptedException { // spawn parsing thread
String metaDescription = metaTags.getProperty("description"); //$NON-NLS-1$
if (metaDescription != null) {
if (metaDescription.length() > SUMMARY_LENGTH) {
@@ -122,19 +83,17 @@ InterruptedException {
}
return summary.toString().trim();
}
-
+
public Reader getReader() throws IOException {
- if (pipeIn == null) {
- pipeInStream = new MyPipedInputStream();
- pipeOutStream = new PipedOutputStream(pipeInStream);
- pipeIn = new InputStreamReader(pipeInStream, "UTF-16BE"); //$NON-NLS-1$
- pipeOut = new OutputStreamWriter(pipeOutStream, "UTF-16BE"); //$NON-NLS-1$
-
- Thread thread = new ParserThread(this);
- thread.start(); // start parsing
- }
+ return new CharArrayReader(writer.toCharArray());
+ }
- return pipeIn;
+ public void parse() throws IOException {
+ try { // parse document to pipeOut
+ HTMLDocument();
+ } catch (Exception e) {
+ setException(e);
+ }
}
void addToSummary(String text) {
@@ -174,7 +133,7 @@ InterruptedException {
}
length += text.length();
- pipeOut.write(text);
+ writer.write(text);
afterSpace = false;
}
@@ -182,9 +141,9 @@ InterruptedException {
void addMetaTag() throws IOException {
metaTags.setProperty(currentMetaTag, currentMetaContent);
if (currentMetaTag.equalsIgnoreCase("keywords")) { //$NON-NLS-1$
- pipeOut.write(' ');
- pipeOut.write(currentMetaContent);
- pipeOut.write(' ');
+ writer.write(' ');
+ writer.write(currentMetaContent);
+ writer.write(' ');
}
currentMetaTag = null;
currentMetaContent = null;
@@ -200,7 +159,7 @@ InterruptedException {
String space = afterTag ? eol : " "; //$NON-NLS-1$
length += space.length();
- pipeOut.write(space);
+ writer.write(space);
afterSpace = true;
}
}
diff --git a/org.eclipse.help.base/src_demo/org/apache/lucene/demo/html/ParserThread.java b/org.eclipse.help.base/src_demo/org/apache/lucene/demo/html/ParserThread.java
deleted file mode 100644
index bdbb2e287..000000000
--- a/org.eclipse.help.base/src_demo/org/apache/lucene/demo/html/ParserThread.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package org.apache.lucene.demo.html;
-
-/**
- * Copyright 2004, The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Copyright (c) 2009 IBM Corp.
- * All rights reserved.
- */
-
-/**
-* History
-* 2004 Initial contribution The Apache Software Foundation
-* 2009 Chris Goldthorpe, IBM Corporation, fix for bug 266649
-*/
-
-import java.io.*;
-
-class ParserThread extends Thread {
- HTMLParser parser;
-
- ParserThread(HTMLParser p) {
- parser = p;
- }
-
- public void run() { // convert pipeOut to pipeIn
-
- try { // parse document to pipeOut
- parser.HTMLDocument();
- } catch (Exception e) {
- parser.setException(e);
- }
-
- try {
- parser.summary.setLength(HTMLParser.SUMMARY_LENGTH);
- parser.titleComplete = true;
- parser.pipeOut.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- parser.notifyAll();
- }
-}

Back to the top