mirror of https://github.com/apache/lucene.git
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:
parent
e535a52af6
commit
dc4da65595
|
@ -20,8 +20,25 @@ public class HTMLParser implements HTMLParserConstants {
|
|||
boolean afterTag = false;
|
||||
boolean afterSpace = false;
|
||||
String eol = System.getProperty("line.separator");
|
||||
PipedReader pipeIn = null;
|
||||
PipedWriter pipeOut;
|
||||
Reader pipeIn = null;
|
||||
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 {
|
||||
this(new FileInputStream(file));
|
||||
|
@ -32,7 +49,7 @@ public class HTMLParser implements HTMLParserConstants {
|
|||
getReader(); // spawn parsing thread
|
||||
while (true) {
|
||||
synchronized(this) {
|
||||
if (titleComplete || (length > SUMMARY_LENGTH))
|
||||
if (titleComplete || pipeInStream.full())
|
||||
break;
|
||||
wait(10);
|
||||
}
|
||||
|
@ -46,7 +63,7 @@ InterruptedException {
|
|||
getReader(); // spawn parsing thread
|
||||
while (true) {
|
||||
synchronized(this) {
|
||||
if (titleComplete || (length > SUMMARY_LENGTH))
|
||||
if (titleComplete || pipeInStream.full())
|
||||
break;
|
||||
wait(10);
|
||||
}
|
||||
|
@ -60,7 +77,7 @@ InterruptedException {
|
|||
getReader(); // spawn parsing thread
|
||||
while (true) {
|
||||
synchronized(this) {
|
||||
if (summary.length() >= SUMMARY_LENGTH)
|
||||
if (summary.length() >= SUMMARY_LENGTH || pipeInStream.full())
|
||||
break;
|
||||
wait(10);
|
||||
}
|
||||
|
@ -70,16 +87,18 @@ InterruptedException {
|
|||
|
||||
String sum = summary.toString().trim();
|
||||
String tit = getTitle();
|
||||
if (sum.startsWith(tit))
|
||||
return sum.substring(tit.length());
|
||||
if (sum.startsWith(tit) || sum.equals(""))
|
||||
return tit;
|
||||
else
|
||||
return sum;
|
||||
}
|
||||
|
||||
public Reader getReader() throws IOException {
|
||||
if (pipeIn == null) {
|
||||
pipeIn = new PipedReader();
|
||||
pipeOut = new PipedWriter(pipeIn);
|
||||
pipeInStream = new MyPipedInputStream();
|
||||
pipeOutStream = new PipedOutputStream(pipeInStream);
|
||||
pipeIn = new InputStreamReader(pipeInStream);
|
||||
pipeOut = new OutputStreamWriter(pipeOutStream);
|
||||
|
||||
Thread thread = new ParserThread(this);
|
||||
thread.start(); // start parsing
|
||||
|
@ -405,18 +424,18 @@ null)
|
|||
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() {
|
||||
if (jj_scan_token(ArgQuote2)) return true;
|
||||
if (jj_scan_token(CloseQuote2)) return true;
|
||||
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;
|
||||
SimpleCharStream jj_input_stream;
|
||||
public Token token, jj_nt;
|
||||
|
|
|
@ -84,8 +84,25 @@ public class HTMLParser {
|
|||
boolean afterTag = false;
|
||||
boolean afterSpace = false;
|
||||
String eol = System.getProperty("line.separator");
|
||||
PipedReader pipeIn = null;
|
||||
PipedWriter pipeOut;
|
||||
Reader pipeIn = null;
|
||||
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 {
|
||||
this(new FileInputStream(file));
|
||||
|
@ -96,7 +113,7 @@ public class HTMLParser {
|
|||
getReader(); // spawn parsing thread
|
||||
while (true) {
|
||||
synchronized(this) {
|
||||
if (titleComplete || (length > SUMMARY_LENGTH))
|
||||
if (titleComplete || pipeInStream.full())
|
||||
break;
|
||||
wait(10);
|
||||
}
|
||||
|
@ -110,7 +127,7 @@ InterruptedException {
|
|||
getReader(); // spawn parsing thread
|
||||
while (true) {
|
||||
synchronized(this) {
|
||||
if (titleComplete || (length > SUMMARY_LENGTH))
|
||||
if (titleComplete || pipeInStream.full())
|
||||
break;
|
||||
wait(10);
|
||||
}
|
||||
|
@ -124,7 +141,7 @@ InterruptedException {
|
|||
getReader(); // spawn parsing thread
|
||||
while (true) {
|
||||
synchronized(this) {
|
||||
if (summary.length() >= SUMMARY_LENGTH)
|
||||
if (summary.length() >= SUMMARY_LENGTH || pipeInStream.full())
|
||||
break;
|
||||
wait(10);
|
||||
}
|
||||
|
@ -134,16 +151,18 @@ InterruptedException {
|
|||
|
||||
String sum = summary.toString().trim();
|
||||
String tit = getTitle();
|
||||
if (sum.startsWith(tit))
|
||||
return sum.substring(tit.length());
|
||||
if (sum.startsWith(tit) || sum.equals(""))
|
||||
return tit;
|
||||
else
|
||||
return sum;
|
||||
}
|
||||
|
||||
public Reader getReader() throws IOException {
|
||||
if (pipeIn == null) {
|
||||
pipeIn = new PipedReader();
|
||||
pipeOut = new PipedWriter(pipeIn);
|
||||
pipeInStream = new MyPipedInputStream();
|
||||
pipeOutStream = new PipedOutputStream(pipeInStream);
|
||||
pipeIn = new InputStreamReader(pipeInStream);
|
||||
pipeOut = new OutputStreamWriter(pipeOutStream);
|
||||
|
||||
Thread thread = new ParserThread(this);
|
||||
thread.start(); // start parsing
|
||||
|
|
Loading…
Reference in New Issue