Shinsuke Sugaya 11 роки тому
батько
коміт
16c28adc38

+ 33 - 14
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();
-            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);
-            }
+
+            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.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();

+ 2 - 0
src/main/java/jp/sf/fess/util/InputStreamThread.java

@@ -39,6 +39,8 @@ public class InputStreamThread extends Thread {
     private final List<String> list = new LinkedList<String>();
 
     public InputStreamThread(final InputStream is, final String charset) {
+        super("InputStreamThread");
+
         try {
             br = new BufferedReader(new InputStreamReader(is, charset));
         } catch (final UnsupportedEncodingException e) {