java for和while循环速度非常慢,同时处理来自数据库的更大数据

时间:2017-06-14 16:15:37

标签: java

我有这个java代码:

{"result":{"countColumns":4,"columnLabels":["NAME","ID","IDSECOND","TIME"],"rows":[["Myname","1399675811417","1424733576894","1425215413292"],["Yurname","1399675811417","1438639227874","1497342014341"],...],"tablenameByColum":["NAMES","NAMES","NAMES","NAMES"]},"ID":0,"errors":[]}
这个java代码生成的结果如下所示:例如:

$result = dibi::query(' 
    SELECT `NAME`,
    `ID`,
    `IDSECOND`,
    `TIME`
    FROM `NAMES`;');
$value = $result->fetchAll();
$data = '';
foreach ($value as $item)
{
    $data = $data . '["'.$item->NAME.'","'.$item->ID.'","'.$item->IDSECOND.'","'.$item->TIME.'"],';
} 
$data = substr($data, 0, -1);
$data='['.$data.']'; 

当我需要处理更大的数据(数千个条目)时,会出现问题,慢速,需要大约几分钟才能完成。知道如何减少处理时间吗?

php中的类似代码:

foreach ($value as $item)
{
    $array[] = '["'.$item->NAME.'","'.$item->ID.'","'.$item->IDSECOND.'","'.$item->TIME.'"]';
} 
$array = implode(",", $array);
$data='['.$array.']';

在php中,我可以像这样减少它:

ViewModel

但是现在我想改进java代码以提高效率。我不懂java,所以对新手的任何帮助都非常感谢。非常感谢:))

0 个答案:

没有答案