2
我創建了一個DOM文檔靜態對象,如下面,它使用的javax.xml.parsers *和*的org.w3c.dom API:。遍歷(讀取)靜態DOM文檔對象是否線程安全?
DocumentBuilderFactory docBldrFactry = DocumentBuilderFactory.newInstance();
docBldrObj = docBldrFactry.newDocumentBuilder();
File file = new File(fileDirectory);
// Parse the XML file and return a DOM document object
document = docBldrObj.parse(file);
//FYI, document is declared as private static org.w3c.dom.Document document elsewhere.
上述後來創建後,如果靜態DOM文檔對象由線程共享,但所有線程只是讀取(遍歷)這個文檔,線程安全嗎?
我認爲這是因爲閱讀不應該修改這個共享狀態,但不知道內部是否有一些我不知道的魔術。
謝謝
Damm ...正如我試過的,它似乎不是..似乎只讀(如getNodeValue())的一些API修改狀態。 – huican
如果我只讀(遍歷)文檔,是否有人知道任何線程安全的XML庫? – huican