From c9f1c12cac64e47f3cce4a4c908a8ea40710766a Mon Sep 17 00:00:00 2001 From: Bart Kiers Date: Thu, 18 Jan 2018 11:34:06 +0100 Subject: [PATCH] Possible to provide custom executor service --- src/main/java/liqp/Template.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/liqp/Template.java b/src/main/java/liqp/Template.java index 7641b630..d550de32 100644 --- a/src/main/java/liqp/Template.java +++ b/src/main/java/liqp/Template.java @@ -254,6 +254,10 @@ public String render(boolean convertValueToMap, String key, Object value, Object * @return a string denoting the rendered template. */ public String render(final Map variables) { + return render(variables, Executors.newSingleThreadExecutor(), true); + } + + public String render(final Map variables, ExecutorService executorService, boolean shutdown) { if (this.templateSize > this.protectionSettings.maxTemplateSizeBytes) { throw new RuntimeException("template exceeds " + this.protectionSettings.maxTemplateSizeBytes + " bytes"); @@ -261,8 +265,6 @@ public String render(final Map variables) { final LiquidWalker walker = new LiquidWalker(new CommonTreeNodeStream(root), this.tags, this.filters, this.parseSettings.flavor); - ExecutorService executorService = Executors.newSingleThreadExecutor(); - Callable task = new Callable() { public String call() throws Exception { try { @@ -276,8 +278,8 @@ public String call() throws Exception { } }; - Future future = executorService.submit(task); try { + Future future = executorService.submit(task); return future.get(this.protectionSettings.maxRenderTimeMillis, TimeUnit.MILLISECONDS); } catch (TimeoutException e) { @@ -288,7 +290,9 @@ public String call() throws Exception { throw new RuntimeException("Oops, something unexpected happened: ", t); } finally { - executorService.shutdown(); + if (shutdown) { + executorService.shutdown(); + } } }