jaxp object caching for MessageFactory
Asked Answered
C

1

6

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

Coralyn answered 17/11, 2010 at 9:30 Comment(2)
The javadoc don't say one way or another, which is unfortunate. I suspect a MessageFactory is thread-safe, since that's the convention, but it's hard to be 100% sure.Gentlefolk
@scaffman:But 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?Coralyn
G
4

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.

Gentlefolk answered 17/11, 2010 at 11:45 Comment(2)
Could I also synchronize access to msgFactory to get a SOAPMessage per thread?Coralyn
@user384706: I suppose so, yes, but you'd have to synchronize it manuallyGentlefolk

© 2022 - 2024 — McMap. All rights reserved.