fix #643 ThumbnailManager manages destroy process for generators

This commit is contained in:
Shinsuke Sugaya 2016-08-23 06:39:36 +09:00
parent f80f667963
commit f0bbebc5af
4 changed files with 19 additions and 8 deletions

View file

@ -26,4 +26,5 @@ public interface ThumbnailGenerator {
boolean isAvailable();
void destroy();
}

View file

@ -107,10 +107,12 @@ public class ThumbnailManager {
while (generating) {
try {
thumbnailTaskQueue.take().generate();
} catch (final InterruptedException e1) {
logger.debug("Interupted task.", e1);
} catch (final Exception e2) {
logger.warn("Failed to generage a thumbnail.", e2);
} catch (final InterruptedException e) {
logger.debug("Interupted task.", e);
} catch (final Exception e) {
if (generating) {
logger.warn("Failed to generage a thumbnail.", e);
}
}
}
}, "ThumbnailGenerator");
@ -121,6 +123,18 @@ public class ThumbnailManager {
public void destroy() {
generating = false;
thumbnailGeneratorThread.interrupt();
try {
thumbnailGeneratorThread.join(10000);
} catch (InterruptedException e) {
logger.warn("Thumbnail thread is timeouted.", e);
}
generatorList.forEach(g -> {
try {
g.destroy();
} catch (final Exception e) {
logger.warn("Failed to stop thumbnail generator.", e);
}
});
}
public void generate(final Map<String, Object> docMap) {

View file

@ -25,7 +25,6 @@ import java.util.Timer;
import java.util.TimerTask;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
@ -50,7 +49,6 @@ public class CommandGenerator extends BaseThumbnailGenerator {
destoryTimer = new Timer("CommandGeneratorDestoryTimer-" + System.currentTimeMillis(), true);
}
@PreDestroy
public void destroy() {
destoryTimer.cancel();
destoryTimer = null;

View file

@ -23,7 +23,6 @@ import java.io.IOException;
import java.util.Collection;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.imageio.ImageIO;
import org.codelibs.fess.util.ComponentUtil;
@ -90,7 +89,6 @@ public class WebDriverGenerator extends BaseThumbnailGenerator {
}
}
@PreDestroy
public void destroy() {
if (webDriver != null) {
webDriver.quit();