-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template.render() leaving Executor threads active #53
Comments
Thanks @mehtasankets! |
Welcom @bkiers .. Can we have new version published with this change? |
@mehtasankets ah, yeah, that would be nice. How about something like this: bf4a522 (on a separate branch for now) |
@bkiers yes, above fix looks good to me.. |
The current release, 0.7.2, already has the shutdown of the exe-service: public String render(final Map<String, Object> variables) {
if (this.templateSize > this.protectionSettings.maxTemplateSizeBytes) {
throw new RuntimeException("template exceeds " + this.protectionSettings.maxTemplateSizeBytes + " bytes");
}
final LiquidWalker walker = new LiquidWalker(new CommonTreeNodeStream(root), this.tags, this.filters, this.parseSettings.flavor);
ExecutorService executorService = Executors.newSingleThreadExecutor();
Callable<String> task = new Callable<String>() {
public String call() throws Exception {
try {
LNode node = walker.walk();
Object rendered = node.render(new TemplateContext(protectionSettings, renderSettings, parseSettings.flavor, variables));
return rendered == null ? "" : String.valueOf(rendered);
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
};
Future<String> future = executorService.submit(task);
try {
return future.get(this.protectionSettings.maxRenderTimeMillis, TimeUnit.MILLISECONDS);
}
catch (TimeoutException e) {
throw new RuntimeException("exceeded the max amount of time (" +
this.protectionSettings.maxRenderTimeMillis + " ms.)");
}
catch (Throwable t) {
throw new RuntimeException("Oops, something unexpected happened: ", t);
}
finally {
executorService.shutdown();
}
} Or do you want a new release of master? |
I would actually need a new version with Would you kindly provide a new jar? |
If you only need the JAR, you can assemble it yourself by doing a If you want a new version in in Maven Central, I'll need to ask someone else. |
I would need it via maven central as I have different environments where I run my program and otherwise I'll have to install it everywhere. |
OK, I've asked for a new release to Maven Central: #72 |
Template.render() method is creating a separate thread which is not getting closed explicitly. Method should ideally call executorService.shutdown() explicitly to properly close the thread.
Not closing threads explicitly is causing multiple threads to be alive in the system and causes problems at the time of closing the process.
The text was updated successfully, but these errors were encountered: