Author: julien_viet
Date: 2011-06-09 17:40:48 -0400 (Thu, 09 Jun 2011)
New Revision: 6622
Modified:
components/pc/branches/2.2.x/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/PortletResponseImpl.java
Log:
GTNPC-65 : Improve the DocumentBuilder creation in PortletResponseImpl
Modified:
components/pc/branches/2.2.x/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/PortletResponseImpl.java
===================================================================
---
components/pc/branches/2.2.x/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/PortletResponseImpl.java 2011-06-09
21:24:49 UTC (rev 6621)
+++
components/pc/branches/2.2.x/portlet/src/main/java/org/gatein/pc/portlet/impl/jsr168/api/PortletResponseImpl.java 2011-06-09
21:40:48 UTC (rev 6622)
@@ -29,10 +29,12 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import java.lang.reflect.UndeclaredThrowableException;
import javax.portlet.PortletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponseWrapper;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
/**
@@ -42,6 +44,22 @@
public abstract class PortletResponseImpl implements PortletResponse
{
+ /** Keep a document builder in a thread local as it can create contention during its
creation. */
+ private static final ThreadLocal<DocumentBuilder> builder = new
ThreadLocal<DocumentBuilder>()
+ {
+ protected DocumentBuilder initialValue()
+ {
+ try
+ {
+ return DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ }
+ catch (ParserConfigurationException e)
+ {
+ throw new UndeclaredThrowableException(e);
+ }
+ }
+ };
+
/** . */
protected final PortletInvocation invocation;
@@ -117,15 +135,7 @@
{
if (doc == null)
{
- try
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- doc = factory.newDocumentBuilder().newDocument();
- }
- catch (ParserConfigurationException e)
- {
- throw new IllegalStateException("Could not create a document builder
factory", e);
- }
+ doc = builder.get().newDocument();
}
//
Show replies by date