JAX-WS - how to improve performance when creating a lot of xjc java objects?
In my schema I have defined an element which consists of a sequence of other elements. I am creating a JAX-WS webservice, so I am generating java classes from my schema using xjc.
Once the classes are generated, I have a loop in my service handler which creates several thousand instances of one of these generated classes, and each instance has a getItems() method which returns a List and I add some items to each.
The response XML looks something like this:
<MyElement>
<Item name="item1">texthere</Item>
<Item name="item2">texthere&l开发者_JAVA百科t;/Item>
<Item name="item3">texthere</Item>
<Item name="item4">texthere</Item>
</MyElement>
<MyElement>
<Item name="item1">texthere</Item>
<Item name="item2">texthere</Item>
<Item name="item3">texthere</Item>
<Item name="item4">texthere</Item>
</MyElement>
etc.
This element appears several thousand times.
My question is about performance:
How can I decrease the amount of time it takes to generate these objects and return the XML response? Currently it takes around 40 seconds for 50,000 MyElement instances. Each MyElement actually has around 10 Item elements, so there are nearly 500,000 objects in total. I've done some profiling and have found that about 10-15 seconds of this are during marshalling the objects and 15-20 seconds to add them to the network stream.
Is there a way to decrease the memory usage? Creating all these jaxb object instances for each MyElement and also each Item element within them uses a lot of memory, is there a better way?
Thank you for helping :)
1)Have a look at this blog it may help you to solve your problem
2)Also why dont u try json its really faster instead of xml
精彩评论