兴趣点相关的code座运行速度慢死 [英] A POI related code block running dead slow

查看:103
本文介绍了兴趣点相关的code座运行速度慢死的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面我有一块含code座的循环:

I have below piece of code block containing loops:

Row row = null;
Cell cell = null;
String dataVal = null;
String[] temp = null;

for (int j = 0; j < this.myDataValues.size(); j++) {
  row = sheet.createRow(rownum++);
  temp = this.finalRowValues.get(j);

   for (int i = 0; i < 4; i++) {
       cell = row.createCell(i);

       dataVal = temp[i];

            if (NumberUtils.isNumber(dataVal)) {
                double d = Double.valueOf(dataVal);
                cell.setCellValue(d);
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                cell.setCellStyle(styles.get("currency"));
            } else if (isValidDate(dataVal)) {
                cell.setCellValue(dataVal);
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                cell.setCellStyle(styles.get("date"));
            } else {
                cell.setCellValue(temp[i]);
                cell.setCellType(Cell.CELL_TYPE_STRING);
                cell.setCellStyle(styles.get("data"));
            }
            sheet.autoSizeColumn(i);
        }
    }

其中, myDataValues​​ 列表的String [] 包含4个值每个的String [] 对象。

Where myDataValues is a List of String[] with each String[] object containing 4 values.

我在Rational Application Developer版本8和Apache POI 3.8运行此。

I am running this in Rational Application Developer version 8 and Apache POI 3.8.

有在 myDataValues​​ 5500左右的元素这是一个pretty较小的值,我相信。

There are around 5500 elements in myDataValues which is a pretty small value I believe.

不过,这code座正在更多然后一个小时运行。

However, this code block is taking more then a hour to run.

我觉得有什么错。 5500元每包含4个元素应该跑得快pretty而且应该是几分钟的问题。可能是什么可能的原因?有没有一种方法,使此块跑得更快?

I think there is something wrong with this. 5500 elements with each containing 4 elements should run pretty fast and should be a question of several minutes. What could be the possible cause? Is there a way to make this block run faster?

有什么错与机器的可用内存或任何其他此类问题。一切都按预期工作,我已经验证它。问题是只有这一块。

There is nothing wrong with available memory of the machine or any other such issues. Everything is working as expected and I have verified it. The issue is in this block only.

推荐答案

您的处理是非常缓慢的,因为你调用 autoSizeColumn 的每一行。从<一个href=\"http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Sheet.html#autoSizeColumn%28int%29\">Javadocs为 autoSizeColumn 方法:

Your processing is very slow because you're calling autoSizeColumn for every row. From the Javadocs for the autoSizeColumn method:

此过程可以在大张的速度相对较慢,所以这应该
  通常只被称为每列一次,月底你
  处理。

This process can be relatively slow on large sheets, so this should normally only be called once per column, at the end of your processing.

将到 autoSizeColumn 的调用,创建行,在自己的循环只能在循环之外列。这将最大限度地减少调用此方法并提高你的表现。

Place the calls to autoSizeColumn outside of the loop that creates the rows, in its own for loop only on the columns. This will minimize calls to this method and improve your performance.

这篇关于兴趣点相关的code座运行速度慢死的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆