From: David ‘Bombe’ Roden Date: Sun, 12 Dec 2010 16:22:13 +0000 (+0100) Subject: Synchronize template access to prevent multiple copies appearing in the HTML. X-Git-Tag: beta-freefall-0.6.2-1~195 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d7df2d32e1986db76e36103167b41f0edc5d831d;p=Sone.git Synchronize template access to prevent multiple copies appearing in the HTML. --- diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java index 7c96d56..ec0145a 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java @@ -90,14 +90,16 @@ public class GetPostAjaxPage extends JsonPage { jsonPost.put("sone", post.getSone().getId()); jsonPost.put("recipient", (post.getRecipient() == null) ? null : post.getRecipient().getId()); jsonPost.put("time", post.getTime()); - postTemplate.set("post", post); StringWriter stringWriter = new StringWriter(); - try { - postTemplate.render(stringWriter); - } catch (TemplateException te1) { - /* TODO - shouldn’t happen. */ - } finally { - Closer.close(stringWriter); + synchronized (postTemplate) { + postTemplate.set("post", post); + try { + postTemplate.render(stringWriter); + } catch (TemplateException te1) { + /* TODO - shouldn’t happen. */ + } finally { + Closer.close(stringWriter); + } } jsonPost.put("html", stringWriter.toString()); return jsonPost; diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java index 77b3ada..0963b09 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java @@ -92,14 +92,16 @@ public class GetReplyAjaxPage extends JsonPage { jsonReply.put("postId", reply.getPost().getId()); jsonReply.put("soneId", reply.getSone().getId()); jsonReply.put("time", reply.getTime()); - replyTemplate.set("reply", reply); StringWriter stringWriter = new StringWriter(); - try { - replyTemplate.render(stringWriter); - } catch (TemplateException te1) { - /* TODO - shouldn’t happen. */ - } finally { - Closer.close(stringWriter); + synchronized (replyTemplate) { + replyTemplate.set("reply", reply); + try { + replyTemplate.render(stringWriter); + } catch (TemplateException te1) { + /* TODO - shouldn’t happen. */ + } finally { + Closer.close(stringWriter); + } } return jsonReply.put("html", stringWriter.toString()); }