Adding repetitive XML fragment to a root (Performance improvement Issue)
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mayank_kumar
Posted On:   Thursday, January 6, 2005 01:49 PM

Hi everyone, I am using JDOM API to parse and create the XML documents. Here is the problem. I have a java object say Person with lots of property like firstName, lastName, email, addressline1, addressline2, ..... etc. In my EJB finder method the query returns a collection which contains lots of person objects. I need to process those Person objects, retrieve their properties and put them in a root tag. Straight forward coding would be something like: Collection personCol = findByfirstName(name); Element rootElem = new Element("PersonList"); Iterator iter = personCol.iterator(); while(iter.hasnext()) {   More>>

Hi everyone,



I am using JDOM API to parse and create the XML documents.
Here is the problem.



I have a java object say Person with lots of property like firstName, lastName, email, addressline1, addressline2, ..... etc.



In my EJB finder method the query returns a collection which contains lots of person objects. I need to process those Person objects, retrieve their properties and put them in a root tag.



Straight forward coding would be something like:


Collection personCol = findByfirstName(name);

Element rootElem = new Element("PersonList");

Iterator iter = personCol.iterator();

while(iter.hasnext()) {

Person personObj = (Person)iter.next();

Element elem = new Element("Person");

Element firstNameElem = new Element("firstName");

firstNameElem.addContent(personObj.getFirstName());

elem.addContent(firstNameElem);

// and so on for each property

rootElem.addContent(elem);

}


But as you might have guessed this way puts a performance penalty when your collection is very large, say 250 Person objects or something like that and response time for this function becomes about 3 seconds on my system which is very high. Is there a way to improve the above code? I was thinking that may be multiple threads will help. But then how will you split your collection and how many thread you will create for optimized preformance. what criteria you will use because the collection size is not fixed. Is anyone aware of a design pattern or something which will help solve this problem? I will really appreciate it.


Regards

Mayank    <<Less

Re: Adding repetitive XML fragment to a root (Performance improvement Issue)

Posted By:   vinay_salehithal  
Posted On:   Thursday, January 6, 2005 02:51 PM

Is the user waiting while this code executes(real time) or is this a backend operation?

Assuming its an realtime operation, is a asynchronous response possible? i.e. allow user to carry on with his work while this operation goes on in backend, and once this operation is complete inform the user.
(Implementation options JMS, EMail)
About | Sitemap | Contact