I have a static method that I use to process ResultSets and have it give back an object. Sometimes it can get called many times over and over again. For instance, in a current project I am working on, the static method gets called over 56,000 times. For whatever reason, as it gets called over and over and over again the method takes longer and longer to reply.
I've been using the System.currentTimeMillis() to figure out where in the code it keeps getting longer to complete, and though I know that the currentTimeMillis() is not 100% accurate, the time that it takes to complete this part of code slowly and repeatedly will increase with time.
Here is the code:
public static Object createFromResultSet(ResultSet someResultSet, String someIndex) throws SQLException, Exception {
{ ... }
List<Object[]> result = new ArrayList();
List<String> columnNames = new ArrayList();
List<Object> addRow;
// the code below will take longer and longer to complete as the method is called over and over again
while (someResultSet.next()) {
addRow = new ArrayList();
for (int x = 0; x < columnNames.size(); x++) {
if (someResultSet.getObject(x + 1) instanceof Double) {
Double someValue = someResultSet.getDouble(x + 1);
addRow.add(new BigDecimal(someValue).toPlainString());
}
else if (someResultSet.getObject(x + 1) != null) addRow.add(someResultSet.getObject(x + 1).toString());
else addRow.add("");
}
result.add(addRow.toArray());
}
{ ... }
}
Maybe I don't completely understand how static methods work in Java, but I would think that all variables in this method would only be used once within the time that the static method is called (ie, if the method is called again, there are no values carried over from the previous time the method was called). Other than the variables that are being passed in, there are no static variables that are being used that were declared outside the method. However, the method becomes slower and slower over time leading me to believe there is data that is being used from previous calls to this method. In the 56,000 times that it is called in my current project, it can take up to an hour for this report to run.
Something tells me I have something wrong in my logic, but for the likes of me I have no clue what's happening.