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