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.InputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
@ -22,16 +22,17 @@ import helma.objectmodel.TransientNode;
|
||||||
public class XmlUtil {
|
public class XmlUtil {
|
||||||
|
|
||||||
private static final DocumentBuilderFactory domBuilderFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
|
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() {
|
private static synchronized DocumentBuilder getDocumentBuilder() {
|
||||||
if ( domBuilders.containsKey (Thread.currentThread()) ) {
|
DocumentBuilder domBuilder = (DocumentBuilder) domBuilders.get (Thread.currentThread());
|
||||||
return (DocumentBuilder)domBuilders.get (Thread.currentThread());
|
if (domBuilder != null) {
|
||||||
|
return domBuilder;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
DocumentBuilder d = domBuilderFactory.newDocumentBuilder();
|
domBuilder = domBuilderFactory.newDocumentBuilder();
|
||||||
domBuilders.put (Thread.currentThread(),d);
|
domBuilders.put (Thread.currentThread(), domBuilder);
|
||||||
return d;
|
return domBuilder;
|
||||||
} catch ( ParserConfigurationException e ) {
|
} catch ( ParserConfigurationException e ) {
|
||||||
throw new RuntimeException ("Cannot build parser: "+e.toString());
|
throw new RuntimeException ("Cannot build parser: "+e.toString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue