开发者

How to synchronize servlet writes to a common xml file resource without transformer exceptions

I am trying to write a servlet that must update an xml file in my web-apps folder, every time a client requests the update. But since the file is a common resource I get the following erron on mvn:jetty server. I get a Transformer exception which basically says the file is not found because the requested operation cannot be performed on a file with a user-mapped section open. I believe this is a windows system message to ensure thread safety.

javax.xml.transform.TransformerException: java.io.FileNotFoundException: C:\User
s\Anubhav\workspace2\blogping-dist (eng)\dreamapp\src\main\webapp\xyz.xml (T
he requested operation cannot be performed on a file with a user-mapped section                       
open)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutpu
tHandler(TransformerImpl.java:489)
        at com.sun.org.apache.xalan.internal.xslt开发者_如何学Goc.trax.TransformerImpl.transfor
m(TransformerImpl.java:298)

Any suggestions to help synchronize access to it?

I looked up transformer objects bottlenecks...but didnt find much on it.

Thanks


  • Make sure you close the stream to the file (fileOutputStream.close())
  • Synchronize writes. Use synchronized(lockObject) or lock.lock()

I would question if the design of the app is good if writes to a common file are required on each request. This is a potential bottleneck and you should try to avoid it. For example consider a transactional database instead of a file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜