ensure termination of pdf parser to avoid deadlocking of other processes during search result preparation

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7958 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent 2c4a672fe2
commit 8a428d3e77

@ -74,7 +74,7 @@ public class pdfParser extends AbstractParser implements Parser {
throw new Parser.Failure("Not enough Memory available for pdf parser: " + MemoryControl.available(), location); throw new Parser.Failure("Not enough Memory available for pdf parser: " + MemoryControl.available(), location);
// create a pdf parser // create a pdf parser
PDDocument pdfDoc = null; final PDDocument pdfDoc;
//final PDFParser pdfParser; //final PDFParser pdfParser;
try { try {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY); Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
@ -125,13 +125,21 @@ public class pdfParser extends AbstractParser implements Parser {
if (docTitle == null || docTitle.length() == 0) { if (docTitle == null || docTitle.length() == 0) {
docTitle = MultiProtocolURI.unescape(location.getFileName()); docTitle = MultiProtocolURI.unescape(location.getFileName());
} }
CharBuffer writer = null; final CharBuffer writer = new CharBuffer();
try { try {
// create a writer for output // create a writer for output
PDFTextStripper stripper = null; final PDFTextStripper stripper = new PDFTextStripper();
writer = new CharBuffer(); // we start the pdf parsing in a separate thread to ensure that it can be terminated
stripper = new PDFTextStripper(); final Thread t = new Thread() {
stripper.writeText(pdfDoc, writer); // may throw a NPE public void run() {
try {
stripper.writeText(pdfDoc, writer); // may throw a NPE
} catch (final Throwable e) {}
}
};
t.start();
t.join(3000);
if (t.isAlive()) t.interrupt();
pdfDoc.close(); pdfDoc.close();
writer.close(); writer.close();
} catch (final IOException e) { } catch (final IOException e) {
@ -149,7 +157,6 @@ public class pdfParser extends AbstractParser implements Parser {
} finally { } finally {
try {pdfDoc.close();} catch (final IOException e) {} try {pdfDoc.close();} catch (final IOException e) {}
} }
pdfDoc = null;
String[] docKeywords = null; String[] docKeywords = null;
if (docKeywordStr != null) { if (docKeywordStr != null) {

Loading…
Cancel
Save