wood burning stoves 2.0*
The moose likes Java in General and the fly likes Optimisation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Optimisation" Watch "Optimisation" New topic
Author

Optimisation

sucheta shanbhag
Greenhorn

Joined: Sep 28, 2007
Posts: 18
I have a resultset returned with more than 500 rows.
I am iterating over the resultset to create objcte for each row in the resultset and adding to a list.
Test test=null;
while(rs.next())

{
test=new Test();
//reading from resultset and making a object
test.setProp1(rs.getString(1));
test.setProp2(rs.getString(2));
list.add(test);


}
But this entire process is taking about 22,000 msec.
I feel the object creation is taking a long time,any suggestion on how to optimise this while loop.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

More likely its the network connection to the database. Creating 500 objects in a loop should be pretty fast. So, step one in any performance optimisation is first find out where the bottleneck is.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

sucheta shanbhag wrote:I feel the object creation is taking a long time,any suggestion on how to optimise this while loop.

Object creation time is solely depends upon what the object constructor do. If you have doubt about the Test object creation, then find out the time taken by the constructor call.
Otherwise, Paul is correct, pointing the the time taken by database resultset.

And I think, you shouldn't worry about such micro optimization..


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
sucheta shanbhag
Greenhorn

Joined: Sep 28, 2007
Posts: 18
juts before the while loop I execute a query wch returns the result in some milisec..so I dont think conn is a prob here ...
stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
juts before the while loop I execute a query wch returns the result in some milisec
Was it a select query? Because one thing is when you push a string to the server, and the other - you get a list of objects from server.
sucheta shanbhag
Greenhorn

Joined: Sep 28, 2007
Posts: 18
yes its a select query ,I guess I need to optimise the query !!
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
The original post describes a process which starts with having the result set. And if we already have a result set doesn't that imply that any issues with network connectivity to the database are in the past? Is the problem properly stated here?
stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
Your ResultSet is connected to DB. If you want to avoid this, you can use cached version of result set.
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
stanislav bashkirtsev wrote:Your ResultSet is connected to DB. If you want to avoid this, you can use cached version of result set.


Ahh, ok. I just figured that having a result set meant that you had already done your query and extracted all the data into java. I guess I have some research to do.

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Ahh, ok. I just figured that having a result set meant that you had already done your query and extracted all the data into java.

No, it doesn't mean this. It means you have done your query, but till you start to move through the result set no data has made its way off the database an on to your application.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

stanislav bashkirtsev wrote:Your ResultSet is connected to DB. If you want to avoid this, you can use cached version of result set.


If the issue is the connection this will not speed the process up, the data still needs to be pulled from the database.

Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Paul Sturrock wrote:
stanislav bashkirtsev wrote:Your ResultSet is connected to DB. If you want to avoid this, you can use cached version of result set.


If the issue is the connection this will not speed the process up, the data still needs to be pulled from the database.



Ok that much is clear now, thanks. Still, if you wanted to isolate database connectivity issues from the rest of the process, as one possible way to identify the bottleneck, then it would seem the cached result set would be the way to go. agreed?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Optimisation
 
Similar Threads
how to use logic:iterate for ArrayLists withing Collection
how to improve my program code ?
HashMap and the While Loop Story
Result Set problems
Vector and JDBC problem?