File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Optimisation

 
sucheta shanbhag
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
sucheta shanbhag
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes its a select query ,I guess I need to optimise the query !!
 
Fred Hamilton
Ranch Hand
Posts: 684
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your ResultSet is connected to DB. If you want to avoid this, you can use cached version of result set.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 684
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic