From cffad9d4b192cbfa61339fe4ca34985c11d5c420 Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Wed, 23 Sep 2015 13:17:37 +0200 Subject: [PATCH] Limit the number of ScriptEngine instances to the number of threads This commit makes ThreadLocal engineHolder ScriptTemplateView field static in order to limit the maximum number of ScriptEngine instances to the number of threads, regardless of the number of view instances. Issue: SPR-13487 --- .../web/servlet/view/script/ScriptTemplateView.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java index bd0e7093f9..e9a5096cc7 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java @@ -69,8 +69,9 @@ public class ScriptTemplateView extends AbstractUrlBasedView { private static final String DEFAULT_RESOURCE_LOADER_PATH = "classpath:"; + private static final ThreadLocal engineHolder = + new NamedThreadLocal("ScriptTemplateView engine"); - private final ThreadLocal engineHolder = new NamedThreadLocal("ScriptTemplateView engine"); private ScriptEngine engine; @@ -235,10 +236,10 @@ public class ScriptTemplateView extends AbstractUrlBasedView { protected ScriptEngine getEngine() { if (Boolean.FALSE.equals(this.sharedEngine)) { - ScriptEngine engine = this.engineHolder.get(); + ScriptEngine engine = engineHolder.get(); if (engine == null) { engine = createEngineFromName(); - this.engineHolder.set(engine); + engineHolder.set(engine); } return engine; }