From e915feb1602a7d88c39623da055fe68af422d27c Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Sun, 5 Oct 2014 01:13:30 +0200 Subject: Introduce at least a semblance of thread-safety. --- org/madore/damlengine/WeblogServlet.java | 35 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'org/madore/damlengine/WeblogServlet.java') diff --git a/org/madore/damlengine/WeblogServlet.java b/org/madore/damlengine/WeblogServlet.java index 6b9b738..9cf1a75 100644 --- a/org/madore/damlengine/WeblogServlet.java +++ b/org/madore/damlengine/WeblogServlet.java @@ -28,7 +28,7 @@ import javax.servlet.http.HttpServletResponse; public class WeblogServlet extends HttpServlet { - private static final long serialVersionUID = 2014100406L; + private static final long serialVersionUID = 2014100407L; @Override public void doGet(HttpServletRequest request, @@ -36,22 +36,23 @@ public class WeblogServlet extends HttpServlet { throws IOException, ServletException { - DamlEngine.runAsServlet = true; - DamlEngine.appProps = new Properties(); - ServletConfig cfg = getServletConfig(); - for (Enumeration e = cfg.getInitParameterNames() ; e.hasMoreElements() ; ) { - String k = e.nextElement(); - DamlEngine.appProps.setProperty(k, cfg.getInitParameter(k)); - } - - if ( DamlEngine.appProps.getProperty("base_path") != null ) - DamlEngine.basePath = Paths.get(DamlEngine.appProps.getProperty("base_path")); - if ( DamlEngine.basePath == null ) - DamlEngine.basePath = Paths.get(getServletContext().getRealPath("/")); - if ( DamlEngine.appProps.getProperty("template_path") != null ) - DamlEngine.templatePath = Paths.get(DamlEngine.appProps.getProperty("template_path")); - if ( DamlEngine.templatePath == null ) - DamlEngine.templatePath = DamlEngine.basePath.resolve("templates"); + synchronized ( DamlEngine.class ) { if ( DamlEngine.appProps == null ) { + DamlEngine.runAsServlet = true; + DamlEngine.appProps = new Properties(); + ServletConfig cfg = getServletConfig(); + for (Enumeration e = cfg.getInitParameterNames() ; e.hasMoreElements() ; ) { + String k = e.nextElement(); + DamlEngine.appProps.setProperty(k, cfg.getInitParameter(k)); + } + if ( DamlEngine.appProps.getProperty("base_path") != null ) + DamlEngine.basePath = Paths.get(DamlEngine.appProps.getProperty("base_path")); + if ( DamlEngine.basePath == null ) + DamlEngine.basePath = Paths.get(getServletContext().getRealPath("/")); + if ( DamlEngine.appProps.getProperty("template_path") != null ) + DamlEngine.templatePath = Paths.get(DamlEngine.appProps.getProperty("template_path")); + if ( DamlEngine.templatePath == null ) + DamlEngine.templatePath = DamlEngine.basePath.resolve("templates"); + } } response.setContentType("text/html; charset=utf-8"); response.setCharacterEncoding("UTF-8"); -- cgit v1.2.3