Skip to content
Advertisement

Casting a long javax.servlet.jsp.jstl.sql.Result to list of Strings is very slow

The for loop at the end of this is very slow when there are 50k rows. Is there a quicker way to get a list of Strings from the rows of a javax.servlet.jsp.jstl.sql.Result? Use a different collection? Convert the Strings differently?

The query is absolutely fine. I am not including here the custom objects that are used to run it. I can’t change them. I think you only need to know that it returns a Result.

(I didn’t write any of this code.)

JavaScript

…method following member initialisation…

JavaScript

UPDATE: The query only takes 1s whereas the loop takes 30s. result.getRows().getClass() is a java.util.SortedMap[].

Advertisement

Answer

Depending on the implementation of javax.servlet.jsp.jstl.sql.Result#getRows() (for example the Tomcat taglibs at https://github.com/apache/tomcat-taglibs-standard/blob/main/impl/src/main/java/org/apache/taglibs/standard/tag/common/sql/ResultImpl.java#L134) it can be that getRows() does unnecessary work each time you call it.

You could rewrite your extraction loop as

JavaScript

which calls getRows() only once.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement