jaxp object caching for MessageFactory

我的梦境 提交于 2019-12-19 19:04:12

问题


Can the javax.xml.soap.MessageFactory be reused?
I.e.

msgFactory = MessageFactory.newInstance(); 

Can I cache msgFactory and reuse it to create new SOAPMessages as needed?
Also should the msgFactory.createMessage(); be synchronized if it is ok to reuse msgFactory in the code?

UPDATE:
Also in single threaded-code, could I store msgFactory to create SOAPMessages over and over, so as not to create a new instance of MessageFactory each time Thanks


回答1:


There's nothing in the javadoc to say that instances of MessageFactory are thread-safe, so I wouldn't make that assumption.

However, within a single thread, there's nothing to stop you re-using a MessageFactory instance over and over again.



来源:https://stackoverflow.com/questions/4203071/jaxp-object-caching-for-messagefactory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!