我在循环中有以下代码:
final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
final SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final URL resource = this.getClass().getResource("/schema/MySchema_1.0.xsd");
final Schema schema = sf.newSchema(resource);
jaxbUnmarshaller.setSchema(schema);
final JAXBElement<MyObject> unmarshal = (JAXBElement<MyObject>) jaxbUnmarshaller.unmarshal(inputStream);
除了实际的解组之外,其他行可以移到循环之外吗?
Unmarshaller
,SchemaFactory
和Schema
是不可变的和/或线程安全的吗? (此时此代码一次只处理一个流,但将来可以并行执行。)