mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-2879 Use Concurrent API in FreemarkerTemplateEngine
thanks to Mathias Bogaert for the patch git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@719643 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+9
-18
@@ -23,10 +23,9 @@ package org.apache.struts2.components.template;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -55,8 +54,8 @@ public class FreemarkerTemplateEngine extends BaseTemplateEngine {
|
||||
static Class bodyContent = null;
|
||||
private FreemarkerManager freemarkerManager;
|
||||
|
||||
private final HashMap<String, freemarker.template.Template> templates = new HashMap<String, freemarker.template.Template>();
|
||||
private final HashSet<String> missingTemplates = new HashSet<String>();
|
||||
private final Map<String, freemarker.template.Template> templates = new ConcurrentHashMap<String, freemarker.template.Template>();
|
||||
private final Set<String> missingTemplates = new CopyOnWriteArraySet<String>();
|
||||
private boolean freemarkerCaching = false;
|
||||
|
||||
static {
|
||||
@@ -191,28 +190,20 @@ public class FreemarkerTemplateEngine extends BaseTemplateEngine {
|
||||
}
|
||||
|
||||
protected void addToMissingTemplateCache(String templateName) {
|
||||
synchronized(missingTemplates) {
|
||||
missingTemplates.add(templateName);
|
||||
}
|
||||
missingTemplates.add(templateName);
|
||||
}
|
||||
|
||||
protected boolean isTemplateMissing(String templateName) {
|
||||
synchronized(missingTemplates) {
|
||||
return missingTemplates.contains(templateName);
|
||||
}
|
||||
return missingTemplates.contains(templateName);
|
||||
}
|
||||
|
||||
protected void addToCache(String templateName,
|
||||
freemarker.template.Template template) {
|
||||
synchronized(templates) {
|
||||
templates.put(templateName, template);
|
||||
}
|
||||
templates.put(templateName, template);
|
||||
}
|
||||
|
||||
protected freemarker.template.Template findInCache(String templateName) {
|
||||
synchronized(templates) {
|
||||
return templates.get(templateName);
|
||||
}
|
||||
return templates.get(templateName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user