removed memory leak where XmlUtil held strong static
references on transactor threads.
This commit is contained in:
parent
11ba081196
commit
61fd1966c1
1 changed files with 13 additions and 12 deletions
|
@ -2,7 +2,7 @@ package helma.objectmodel.dom;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
|
@ -22,22 +22,23 @@ import helma.objectmodel.TransientNode;
|
|||
public class XmlUtil {
|
||||
|
||||
private static final DocumentBuilderFactory domBuilderFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
|
||||
private static final HashMap domBuilders = new HashMap();
|
||||
private static final WeakHashMap domBuilders = new WeakHashMap();
|
||||
|
||||
private static synchronized DocumentBuilder getDocumentBuilder() {
|
||||
if ( domBuilders.containsKey (Thread.currentThread()) ) {
|
||||
return (DocumentBuilder)domBuilders.get (Thread.currentThread());
|
||||
} else {
|
||||
try {
|
||||
DocumentBuilder d = domBuilderFactory.newDocumentBuilder();
|
||||
domBuilders.put (Thread.currentThread(),d);
|
||||
return d;
|
||||
} catch ( ParserConfigurationException e ) {
|
||||
private static synchronized DocumentBuilder getDocumentBuilder() {
|
||||
DocumentBuilder domBuilder = (DocumentBuilder) domBuilders.get (Thread.currentThread());
|
||||
if (domBuilder != null) {
|
||||
return domBuilder;
|
||||
} else {
|
||||
try {
|
||||
domBuilder = domBuilderFactory.newDocumentBuilder();
|
||||
domBuilders.put (Thread.currentThread(), domBuilder);
|
||||
return domBuilder;
|
||||
} catch ( ParserConfigurationException e ) {
|
||||
throw new RuntimeException ("Cannot build parser: "+e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Document newDocument() {
|
||||
DocumentBuilder d = getDocumentBuilder();
|
||||
return d.newDocument();
|
||||
|
|
Loading…
Add table
Reference in a new issue