MessageFactory的jaxp对象缓存 [英] jaxp object caching for MessageFactory

查看:136
本文介绍了MessageFactory的jaxp对象缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以重复使用 javax.xml.soap.MessageFactory 吗?

I.e。

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

msgFactory = MessageFactory.newInstance(); 

我可以缓存msgFactory并根据需要重新使用它来创建新的SOAPMessages?

如果在代码中重复使用msgFactory可以同时执行 msgFactory.createMessage();

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?

更新:

同样在单线程代码中,我可以存储msgFactory来重复创建SOAPMessage,以免每次
创建一个新的MessageFactory实例感谢

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

推荐答案

在javadoc中没有什么可以说, MessageFactory 是线程安全的,所以我不会做这个假设。

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

然而,在一个线程中,没有什么可以阻止你重新使用 MessageFactory 实例一遍又一遍。

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

这篇关于MessageFactory的jaxp对象缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆