日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

FWK005 parse may not be called while parsing

發布時間:2024/4/17 编程问答 63 豆豆
生活随笔 收集整理的這篇文章主要介紹了 FWK005 parse may not be called while parsing 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://xieshaohu.wordpress.com/2011/04/21/fwk005-parse-may-not-be-called-while-parsing/

FWK005 parse may not be called while?parsing.


最近在使用javax.xml.parsers.DocumentBuilder解析xml文件的時候偶爾會出錯:

org.xml.sax.SAXException: FWK005 parse may not be called while parsing.at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:263)at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208) ...

跟蹤了一下代碼,發現這個異常是在com.sun.org.apache.xerces.internal.parsers.DTDConfiguration.parse(DTDConfiguration.java:546)拋出來的。該段代碼結構如下:

if(fParseInProgress) {throw new XNIException("FWK005 parse may not be called while parsing."); }fParseInProgress = true;// 解析xml文件finally {fParseInProgress = false; }

從程序邏輯來看,如果當前DocumentBuilder對象正在轉換文檔,此時再次請求轉換文檔,那么直接拋出XNIException(“FWK005 parse may not be called while parsing.”);異常。

這個問題也比較好解決,一種是對轉換xml文檔的方法,增加synchronized關鍵字,這樣子不會有兩個線程同時訪問方法。

還有一種方法是創建一個DocumentBuilder類型的ThreadLocal變量,這樣子每個線程都擁有自己的DocumentBuilder對象,能夠同時轉換多個xml文件。代碼如下:

private static ThreadLocal docBuildeIns = new ThreadLocal() {protected DocumentBuilder initialValue() {try {return DocumentBuilderFactory.newInstance().newDocumentBuilder();} catch (ParserConfigurationException e) {String msg = "DocumentBuilder 對象初始化失敗!";log.error(msg, e);throw new IllegalStateException(msg, e);}} };

解析xml文件時的調用方法:

docBuildIns.get().parse(File);

get()方法返回此線程局部變量的當前線程副本中的值。如果變量沒有用于當前線程的值,則先將其初始化為調用 initialValue() 方法返回的值。

?

總結

以上是生活随笔為你收集整理的FWK005 parse may not be called while parsing的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。