Fix for deadlock between indexing thread and parsing

thread that occurs with long titles. Parsing thread waits
for indexing thread to read from pipeIn, indexing thread
waits for summary. This fixes bug #24301


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150136 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christoph Goller 2003-11-23 15:37:26 +00:00
parent e535a52af6
commit dc4da65595
2 changed files with 62 additions and 24 deletions

View File

@ -20,8 +20,25 @@ public class HTMLParser implements HTMLParserConstants {
boolean afterTag = false; boolean afterTag = false;
boolean afterSpace = false; boolean afterSpace = false;
String eol = System.getProperty("line.separator"); String eol = System.getProperty("line.separator");
PipedReader pipeIn = null; Reader pipeIn = null;
PipedWriter pipeOut; Writer pipeOut;
private MyPipedInputStream pipeInStream = null;
private PipedOutputStream pipeOutStream = null;
private class MyPipedInputStream extends PipedInputStream{
public MyPipedInputStream(){
super();
}
public MyPipedInputStream(PipedOutputStream src) throws IOException{
super(src);
}
public boolean full() throws IOException{
return this.available() >= PipedInputStream.PIPE_SIZE;
}
}
public HTMLParser(File file) throws FileNotFoundException { public HTMLParser(File file) throws FileNotFoundException {
this(new FileInputStream(file)); this(new FileInputStream(file));
@ -32,7 +49,7 @@ public class HTMLParser implements HTMLParserConstants {
getReader(); // spawn parsing thread getReader(); // spawn parsing thread
while (true) { while (true) {
synchronized(this) { synchronized(this) {
if (titleComplete || (length > SUMMARY_LENGTH)) if (titleComplete || pipeInStream.full())
break; break;
wait(10); wait(10);
} }
@ -46,7 +63,7 @@ InterruptedException {
getReader(); // spawn parsing thread getReader(); // spawn parsing thread
while (true) { while (true) {
synchronized(this) { synchronized(this) {
if (titleComplete || (length > SUMMARY_LENGTH)) if (titleComplete || pipeInStream.full())
break; break;
wait(10); wait(10);
} }
@ -60,7 +77,7 @@ InterruptedException {
getReader(); // spawn parsing thread getReader(); // spawn parsing thread
while (true) { while (true) {
synchronized(this) { synchronized(this) {
if (summary.length() >= SUMMARY_LENGTH) if (summary.length() >= SUMMARY_LENGTH || pipeInStream.full())
break; break;
wait(10); wait(10);
} }
@ -70,16 +87,18 @@ InterruptedException {
String sum = summary.toString().trim(); String sum = summary.toString().trim();
String tit = getTitle(); String tit = getTitle();
if (sum.startsWith(tit)) if (sum.startsWith(tit) || sum.equals(""))
return sum.substring(tit.length()); return tit;
else else
return sum; return sum;
} }
public Reader getReader() throws IOException { public Reader getReader() throws IOException {
if (pipeIn == null) { if (pipeIn == null) {
pipeIn = new PipedReader(); pipeInStream = new MyPipedInputStream();
pipeOut = new PipedWriter(pipeIn); pipeOutStream = new PipedOutputStream(pipeInStream);
pipeIn = new InputStreamReader(pipeInStream);
pipeOut = new OutputStreamWriter(pipeOutStream);
Thread thread = new ParserThread(this); Thread thread = new ParserThread(this);
thread.start(); // start parsing thread.start(); // start parsing
@ -405,18 +424,18 @@ null)
finally { jj_save(1, xla); } finally { jj_save(1, xla); }
} }
final private boolean jj_3_1() {
if (jj_scan_token(ArgQuote1)) return true;
if (jj_scan_token(CloseQuote1)) return true;
return false;
}
final private boolean jj_3_2() { final private boolean jj_3_2() {
if (jj_scan_token(ArgQuote2)) return true; if (jj_scan_token(ArgQuote2)) return true;
if (jj_scan_token(CloseQuote2)) return true; if (jj_scan_token(CloseQuote2)) return true;
return false; return false;
} }
final private boolean jj_3_1() {
if (jj_scan_token(ArgQuote1)) return true;
if (jj_scan_token(CloseQuote1)) return true;
return false;
}
public HTMLParserTokenManager token_source; public HTMLParserTokenManager token_source;
SimpleCharStream jj_input_stream; SimpleCharStream jj_input_stream;
public Token token, jj_nt; public Token token, jj_nt;

View File

@ -84,8 +84,25 @@ public class HTMLParser {
boolean afterTag = false; boolean afterTag = false;
boolean afterSpace = false; boolean afterSpace = false;
String eol = System.getProperty("line.separator"); String eol = System.getProperty("line.separator");
PipedReader pipeIn = null; Reader pipeIn = null;
PipedWriter pipeOut; Writer pipeOut;
private MyPipedInputStream pipeInStream = null;
private PipedOutputStream pipeOutStream = null;
private class MyPipedInputStream extends PipedInputStream{
public MyPipedInputStream(){
super();
}
public MyPipedInputStream(PipedOutputStream src) throws IOException{
super(src);
}
public boolean full() throws IOException{
return this.available() >= PipedInputStream.PIPE_SIZE;
}
}
public HTMLParser(File file) throws FileNotFoundException { public HTMLParser(File file) throws FileNotFoundException {
this(new FileInputStream(file)); this(new FileInputStream(file));
@ -96,7 +113,7 @@ public class HTMLParser {
getReader(); // spawn parsing thread getReader(); // spawn parsing thread
while (true) { while (true) {
synchronized(this) { synchronized(this) {
if (titleComplete || (length > SUMMARY_LENGTH)) if (titleComplete || pipeInStream.full())
break; break;
wait(10); wait(10);
} }
@ -110,7 +127,7 @@ InterruptedException {
getReader(); // spawn parsing thread getReader(); // spawn parsing thread
while (true) { while (true) {
synchronized(this) { synchronized(this) {
if (titleComplete || (length > SUMMARY_LENGTH)) if (titleComplete || pipeInStream.full())
break; break;
wait(10); wait(10);
} }
@ -124,7 +141,7 @@ InterruptedException {
getReader(); // spawn parsing thread getReader(); // spawn parsing thread
while (true) { while (true) {
synchronized(this) { synchronized(this) {
if (summary.length() >= SUMMARY_LENGTH) if (summary.length() >= SUMMARY_LENGTH || pipeInStream.full())
break; break;
wait(10); wait(10);
} }
@ -134,16 +151,18 @@ InterruptedException {
String sum = summary.toString().trim(); String sum = summary.toString().trim();
String tit = getTitle(); String tit = getTitle();
if (sum.startsWith(tit)) if (sum.startsWith(tit) || sum.equals(""))
return sum.substring(tit.length()); return tit;
else else
return sum; return sum;
} }
public Reader getReader() throws IOException { public Reader getReader() throws IOException {
if (pipeIn == null) { if (pipeIn == null) {
pipeIn = new PipedReader(); pipeInStream = new MyPipedInputStream();
pipeOut = new PipedWriter(pipeIn); pipeOutStream = new PipedOutputStream(pipeInStream);
pipeIn = new InputStreamReader(pipeInStream);
pipeOut = new OutputStreamWriter(pipeOutStream);
Thread thread = new ParserThread(this); Thread thread = new ParserThread(this);
thread.start(); // start parsing thread.start(); // start parsing