java - What are likely causes of StringBuilder and ResultSet performance issues -
I am looping through ResultSet in Java; Which is returning approximately 30 rows with 17 columns per line (all string data) for testing purposes, I am manually using stringbirders to create one XML string from the results and to eliminate these interactions For about 36 seconds I have been literally experimenting.
Note: I know that this is not the best way to go out the best way to get XML out of a database or to get the resulting XML - but I have slow performance of it regardless Curiosity is there.
Updates: According to the responses, I have to address the following: Time to run the query is less than one second, and before and after each section of my code In order to narrow it it was a system serial (Timmill). 36 seconds is completely within the code below.
ResultSetMetaData rsmeta = rset.getMetaData (); Stringbilder resultbuilder = new stringbilder (); Resultbuilder.append ("& lt ;? Xml version = \" 1.0 \ "? & Gt; ROWSET & gt;"); If (numColumn! = 0) {while (rset.next ()) {resultbuilder.append ("& lt; ROW & gt;"); For (int i = 0; i <= numColumns -1; i ++) {columnName = rsmeta.getColumnName (i + 1); ResultBuilder.append ("& lt;"); ResultBuilder.append (columnName); Resultbuilder.append ("& gt;"); Resultbuilder.append (rset.getString (i + 1)); ResultBuilder.append ("& lt; /"); ResultBuilder.append (columnName); Resultbuilder.append ("& gt;"); } Resultbuilder.append ("& lt; / ROW & gt;"); NumRows + = 1; }} And {stmt.close (); WsConn.close (); Return "No Results"; } Update: The suggestions I have received - This code gives approximately equal time or takes half a second. stringbilder resultbuilder = new stringbilder (); Resultbuilder.append ("& lt ;? Xml version = \" 1.0 \ "? & Gt; ROWSET & gt;"); If (numColumn! = 0) {while (rset.next ()) {resultbuilder.append ("& lt; ROW & gt;"); For (int i = 0; i & lt; = numColumns -1; i ++) {// columnname = rsmeta.getColumnName (i + 1); ResultBuilder.append ("& lt;"); ResultBuilder.append ("TestColumnName"); Resultbuilder.append ("& gt;"); //resultBuilder.append(rset.getString (i+1)); ResultBuilder.append ("TestData"); ResultBuilder.append ("& lt; /"); ResultBuilder.append ("TestColumnName"); Resultbuilder.append ("& gt;"); } Resultbuilder.append ("& lt; / ROW & gt;"); NumRows + = 1; }} And {stmt.close (); WsConn.close (); Return "No Results"; }
I had finished everything in the previous exam, it was the time when the test was replaced with realistic number of iterations (160, with small tests done by me Maximum rows are returned). Now the question is what can be about the set of results that slow down like this.
while (numrows & lt; = 160) {// as above}
Update: As I suggested That is, I am closing this question because the title does not reflect the problem that takes the problem.
I am very doubtful that stringbugler
is the culprit here. Java uses it extensively, I have used it extensively, I have written it again for my own JVM, and basically it is always able to eat hundreds of millions of letters per second.
I think your trouble comes from database access. When you run a query and receive a ResultSet
, it does not necessarily mean that all data has been received and internally converted into an easy-to-manage memory representation database implementation Based on (and its JDBC driver), ResultSet
may result in promise of many results, which are dynamically generated when ResultSet.next ()
and ResultSet.getString ()
being called methods Is.
Try exploring the results, call all your next to ()
and getString ()
, but your stringbuilder code> If it still takes 36 seconds, then
StringBuilder
is innocent (which I firmly believe is this).
Comments
Post a Comment