Initialize JAXBContext in a post construct method

311 Views Asked by At

I am using JAXB to convert an xml into a java object. Our application is event driven. When some event happens a method in the Parser class is called. We will receive the xml as a byte array.

Since its very costly to create a JAXBContext every time when the event is fired and even meaningless.

So I tried to shift this code to a post construct method. Then I realized JAXBConext.newInstance(Class) throws a JAXBException. Is it a good idea to put the initialization code here? If the creation fails due to some reason there is no meaning in processing the events now.

Is there any other approach?

0

There are 0 best solutions below