Browse Source

Limit the number of ScriptEngine instances to the number of threads

This commit makes ThreadLocal<ScriptEngine> 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
pull/815/merge
Sebastien Deleuze 9 years ago
parent
commit
cffad9d4b1
  1. 7
      spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java

7
spring-webmvc/src/main/java/org/springframework/web/servlet/view/script/ScriptTemplateView.java

@ -69,8 +69,9 @@ public class ScriptTemplateView extends AbstractUrlBasedView { @@ -69,8 +69,9 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
private static final String DEFAULT_RESOURCE_LOADER_PATH = "classpath:";
private static final ThreadLocal<ScriptEngine> engineHolder =
new NamedThreadLocal<ScriptEngine>("ScriptTemplateView engine");
private final ThreadLocal<ScriptEngine> engineHolder = new NamedThreadLocal<ScriptEngine>("ScriptTemplateView engine");
private ScriptEngine engine;
@ -235,10 +236,10 @@ public class ScriptTemplateView extends AbstractUrlBasedView { @@ -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;
}

Loading…
Cancel
Save