Skip to content

Commit 018721f

Browse files
authored
Merge pull request #24 from samj1912/test
Create local instances of marshaller/unmarhsaller since they are not thread-safe
2 parents c80fc61 + 0414388 commit 018721f

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

mb-solrquerywriter/src/main/java/org/musicbrainz/search/solrwriter/MBJSONWriter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public void init(NamedList initArgs) {
101101
try {
102102
jsonContext = createJAXBJSONContext();
103103
errorContext = createJAXBErrorContext();
104-
marshaller = createMarshaller();
105104
errorMarshaller = createErrorMarshaller();
106105
} catch (JAXBException ex) {
107106
throw new RuntimeException(ex);

mb-solrquerywriter/src/main/java/org/musicbrainz/search/solrwriter/MBXMLWriter.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ public class MBXMLWriter implements QueryResponseWriter {
7878
*/
7979
private JAXBContext context = null;
8080
protected JAXBContext errorContext = null;
81-
private Unmarshaller unmarshaller = null;
82-
protected Marshaller marshaller = null;
8381
protected Marshaller errorMarshaller = null;
8482
private ObjectFactory objectfactory = null;
8583

@@ -298,9 +296,7 @@ public void init(NamedList initArgs) {
298296
try {
299297
context = createJAXBContext();
300298
errorContext = createJAXBErrorContext();
301-
marshaller = createMarshaller();
302299
errorMarshaller = createErrorMarshaller();
303-
unmarshaller = context.createUnmarshaller();
304300
} catch (JAXBException e) {
305301
throw new RuntimeException(e);
306302
}
@@ -375,8 +371,8 @@ else if (response instanceof SolrDocumentList)
375371

376372
Metadata metadata = metadatalistwrapper.getCompletedMetadata();
377373
metadata.setCreated(now);
378-
379374
try {
375+
Marshaller marshaller = createMarshaller();
380376
marshaller.marshal(metadata, sw);
381377
} catch (JAXBException e) {
382378
e.printStackTrace();
@@ -389,7 +385,12 @@ else if (response instanceof SolrDocumentList)
389385
public void parseSolrResponse(ResultContext con, MetadataListWrapper metadatalistwrapper, SolrQueryRequest req) throws IOException {
390386

391387
DocList doclist = con.getDocList();
392-
388+
Unmarshaller unmarshaller = null;
389+
try {
390+
unmarshaller = context.createUnmarshaller();
391+
} catch (JAXBException e) {
392+
throw new RuntimeException(e);
393+
}
393394
metadatalistwrapper.setCountAndOffset(doclist.matches(),
394395
doclist.offset());
395396

@@ -457,6 +458,12 @@ public void parseSolrResponse(SolrDocumentList doclist, MetadataListWrapper meta
457458

458459
metadatalistwrapper.setCountAndOffset(doclist.getNumFound(),
459460
doclist.getStart());
461+
Unmarshaller unmarshaller = null;
462+
try {
463+
unmarshaller = context.createUnmarshaller();
464+
} catch (JAXBException e) {
465+
throw new RuntimeException(e);
466+
}
460467

461468
List xmlList = metadatalistwrapper.getLiveList();
462469

0 commit comments

Comments
 (0)