You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by jk...@apache.org on 2002/02/05 21:27:48 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/serialize CharInfo.java
jkesselm 02/02/05 12:27:48
Modified: java/src/org/apache/xalan/serialize CharInfo.java
Log:
Bug 5857: Reusing objects that reuse objects has threading concerns.
Three possible solutions: Don't reuse, synchronize reuse, or rewrite
to avoid using the objects in the first place. See comments in code.
Revision Changes Path
1.12 +10 -1 xml-xalan/java/src/org/apache/xalan/serialize/CharInfo.java
Index: CharInfo.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/CharInfo.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- CharInfo.java 24 Oct 2001 19:30:09 -0000 1.11
+++ CharInfo.java 5 Feb 2002 20:27:48 -0000 1.12
@@ -266,7 +266,6 @@
*/
protected void defineEntity(String name, char value)
{
-
CharKey character = new CharKey(value);
m_charToEntityRef.put(character, name);
@@ -278,12 +277,22 @@
/**
* Resolve a character to an entity reference name.
*
+ * This is reusing a stored key object, in an effort to avoid
+ * heap activity. Unfortunately, that introduces a threading risk.
+ * Simplest fix for now is to make it a synchronized method, or to give
+ * up the reuse; I see very little performance difference between them.
+ * Long-term solution would be to replace the hashtable with a sparse array
+ * keyed directly from the character's integer value; see DTM's
+ * string pool for a related solution.
+ *
* @param value character value that should be resolved to a name.
*
* @return name of character entity, or null if not found.
*/
+ synchronized
public String getEntityNameForChar(char value)
{
+ // CharKey m_charKey = new CharKey(); //Alternative to synchronized
m_charKey.setChar(value);
return (String) m_charToEntityRef.get(m_charKey);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org