diff --git a/src/main/java/jp/sf/fess/helper/JobHelper.java b/src/main/java/jp/sf/fess/helper/JobHelper.java index 72b4c7128..6c8d0e799 100644 --- a/src/main/java/jp/sf/fess/helper/JobHelper.java +++ b/src/main/java/jp/sf/fess/helper/JobHelper.java @@ -19,6 +19,8 @@ package jp.sf.fess.helper; import java.io.IOException; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import jp.sf.fess.FessSystemException; import jp.sf.fess.job.JobExecutor; @@ -77,21 +79,38 @@ public class JobHelper { logger.warn("Could not interrupt a thread of an input stream.", e); } - Process process = jobProcess.getProcess(); + + final CountDownLatch latch = new CountDownLatch(1); + final Process process = jobProcess.getProcess(); + new Thread(new Runnable() { + @Override + public void run() { + try { + IOUtils.closeQuietly(process.getInputStream()); + } catch (final Exception e) { + logger.warn("Could not close a process input stream.", + e); + } + try { + IOUtils.closeQuietly(process.getErrorStream()); + } catch (final Exception e) { + logger.warn("Could not close a process error stream.", + e); + } + try { + IOUtils.closeQuietly(process.getOutputStream()); + } catch (final Exception e) { + logger.warn("Could not close a process output stream.", + e); + } + latch.countDown(); + } + }, "ProcessCloser").start(); + try { - IOUtils.closeQuietly(process.getInputStream()); - } catch (final Exception e) { - logger.warn("Could not close a process input stream.", e); - } - try { - IOUtils.closeQuietly(process.getErrorStream()); - } catch (final Exception e) { - logger.warn("Could not close a process error stream.", e); - } - try { - IOUtils.closeQuietly(process.getOutputStream()); - } catch (final Exception e) { - logger.warn("Could not close a process output stream.", e); + latch.await(10, TimeUnit.SECONDS); + } catch (InterruptedException e) { + logger.warn("Interrupted to wait a process.", e); } try { process.destroy(); diff --git a/src/main/java/jp/sf/fess/util/InputStreamThread.java b/src/main/java/jp/sf/fess/util/InputStreamThread.java index b41108aac..5d32a66e4 100644 --- a/src/main/java/jp/sf/fess/util/InputStreamThread.java +++ b/src/main/java/jp/sf/fess/util/InputStreamThread.java @@ -39,6 +39,8 @@ public class InputStreamThread extends Thread { private final List list = new LinkedList(); public InputStreamThread(final InputStream is, final String charset) { + super("InputStreamThread"); + try { br = new BufferedReader(new InputStreamReader(is, charset)); } catch (final UnsupportedEncodingException e) {