Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.*; import javax.xml.parsers.*; import java.io.*; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; public class Main { private static final Lock factoryLock = new ReentrantLock(); public static Document newDomDocument() throws IOException { try { DocumentBuilderFactory factory = newDocumentBuilderFactory(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.newDocument(); } catch (ParserConfigurationException e) { throw new IOException("Can't create new DOM-document.", e); } } public static DocumentBuilderFactory newDocumentBuilderFactory() { factoryLock.lock(); try { return DocumentBuilderFactory.newInstance(); } finally { factoryLock.unlock(); } } }