fix use destroyForcibly
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
+import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@@ -44,6 +45,8 @@ public class CommandGenerator extends BaseThumbnailGenerator {
protected long commandTimeout = 30 * 1000L;// 30sec
+ protected long commandDestroyTimeout = 5 * 1000L;// 5sec
+
protected File baseDir;
private volatile Timer destoryTimer;
@@ -141,7 +144,7 @@ public class CommandGenerator extends BaseThumbnailGenerator {
p = pb.start();
- task = new ProcessDestroyer(p, cmdList);
+ task = new ProcessDestroyer(p, cmdList, commandTimeout);
try {
destoryTimer.schedule(task, commandTimeout);
@@ -177,16 +180,19 @@ public class CommandGenerator extends BaseThumbnailGenerator {
private final List<String> commandList;
- protected ProcessDestroyer(final Process p, final List<String> commandList) {
+ private long timeout;
+
+ protected ProcessDestroyer(final Process p, final List<String> commandList, final long timeout) {
this.p = p;
this.commandList = commandList;
+ this.timeout = timeout;
}
@Override
public void run() {
logger.warn("CommandGenerator is timed out: " + commandList);
try {
- p.destroy();
+ p.destroyForcibly().waitFor(timeout, TimeUnit.MILLISECONDS);
} catch (final Exception e) {
logger.warn("Failed to stop destroyer.", e);
}
@@ -205,4 +211,8 @@ public class CommandGenerator extends BaseThumbnailGenerator {
this.baseDir = baseDir;
}
+ public void setCommandDestroyTimeout(long commandDestroyTimeout) {
+ this.commandDestroyTimeout = commandDestroyTimeout;
+ }
+
}
