• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Optimisation

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes its a select query ,I guess I need to optimise the query !!
 
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic