From d0458047cbbaabbd4514a7a17a75aa1c84fb95fa Mon Sep 17 00:00:00 2001 From: j2blake Date: Sun, 17 Nov 2013 15:27:24 -0500 Subject: [PATCH] =?UTF-8?q?VIVO-552=20Reduce=20=E2=80=9Cmemory=20leak?= =?UTF-8?q?=E2=80=9D=20messages=20at=20shutdown.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Back out the changes - locks up on the develop branch. --- .../config/FreemarkerConfigurationImpl.java | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfigurationImpl.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfigurationImpl.java index 30a40bc85..617a09f6c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfigurationImpl.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/freemarker/config/FreemarkerConfigurationImpl.java @@ -3,7 +3,6 @@ package edu.cornell.mannlib.vitro.webapp.freemarker.config; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -49,22 +48,15 @@ public class FreemarkerConfigurationImpl extends Configuration { private static final Log log = LogFactory .getLog(FreemarkerConfigurationImpl.class); - private final ThreadLocal currentRequestHash = new ThreadLocal<>(); - private final Map rbiMap = Collections - .synchronizedMap(new HashMap()); + private final ThreadLocal rbiRef = new ThreadLocal<>(); - protected void setRequestInfo(HttpServletRequest req) { - currentRequestHash.set(req.hashCode()); - rbiMap.put(req.hashCode(), new RequestBasedInformation(req, this)); - } - - private RequestBasedInformation getRequestInfo() { - return rbiMap.get(currentRequestHash.get()); + void setRequestInfo(HttpServletRequest req) { + rbiRef.set(new RequestBasedInformation(req, this)); } @Override public Object getCustomAttribute(String name) { - Map attribs = getRequestInfo().getCustomAttributes(); + Map attribs = rbiRef.get().getCustomAttributes(); if (attribs.containsKey(name)) { return attribs.get(name); } else { @@ -74,13 +66,13 @@ public class FreemarkerConfigurationImpl extends Configuration { @Override public String[] getCustomAttributeNames() { - Set rbiNames = getRequestInfo().getCustomAttributes().keySet(); + Set rbiNames = rbiRef.get().getCustomAttributes().keySet(); return joinNames(rbiNames, super.getCustomAttributeNames()); } @Override public TemplateModel getSharedVariable(String name) { - Map vars = getRequestInfo().getSharedVariables(); + Map vars = rbiRef.get().getSharedVariables(); if (vars.containsKey(name)) { return vars.get(name); } else { @@ -90,7 +82,7 @@ public class FreemarkerConfigurationImpl extends Configuration { @Override public Set getSharedVariableNames() { - Set rbiNames = getRequestInfo().getSharedVariables().keySet(); + Set rbiNames = rbiRef.get().getSharedVariables().keySet(); @SuppressWarnings("unchecked") Set superNames = super.getSharedVariableNames(); @@ -102,7 +94,7 @@ public class FreemarkerConfigurationImpl extends Configuration { @Override public Locale getLocale() { - return getRequestInfo().getReq().getLocale(); + return rbiRef.get().getReq().getLocale(); } private String[] joinNames(Set nameSet, String[] nameArray) {