fix #1478 use destroyForcibly
This commit is contained in:
parent
fb695477a6
commit
f3d60e13cd
1 changed files with 13 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue