如何在java中加快数据集读取过程

如何在java中加快数据集读取过程,java,Java,我正在从事一个java项目,我必须从excel工作表中读取数据集,以便在项目中稍后使用它们,因此我有一个单独的类用于读取方法,它工作得很好,但需要很长时间(可能10或11分钟) public类readExcel{ 字符串[]excelSheets={“f1.xls”、“f2.xls”、“f3.xls”、“f4.xls”、“f5.xls”、“f6.xls”、“f7.xls”、“f8.xls”、“f9.xls”}; //阅读所有Excel表格 double[][]阵列信号矩阵=新的double[9]

我正在从事一个java项目,我必须从excel工作表中读取数据集,以便在项目中稍后使用它们,因此我有一个单独的类用于读取方法,它工作得很好,但需要很长时间(可能10或11分钟)

public类readExcel{
字符串[]excelSheets={“f1.xls”、“f2.xls”、“f3.xls”、“f4.xls”、“f5.xls”、“f6.xls”、“f7.xls”、“f8.xls”、“f9.xls”};
//阅读所有Excel表格
double[][]阵列信号矩阵=新的double[9][30][13][13];
double[]ArrayDeterminantSigmatrices=新的双精度[9][30][1][1];
double[][]ArrayinVersesigmaMatrix=新的double[9][30][13][13];
double[]arraysSigmaDiagonalMatrices=新的double[9][30][1][13];
double[][]阵列矩阵=新的double[9][30][13];
double[][]阵列组件比例矩阵=新的double[9][1][30];
public void readExcelsheets()引发FileNotFoundException,IOException{
System.out.println(“等待读取文件…”);
阵列信号矩阵();
arrayDeterminantSigmaMatrices();
ArrayinVersesigmaMatrix();
arraysSigmaDiagonalMatrices();
数组矩阵();
阵列组件比例矩阵();
系统输出打印项次(“完成”);
}
public void arraysSigmaMatrices()引发FileNotFoundException、IOException{
对于(int-catrgory=0;catrgory
readExcel是一个单独的类,用于在程序运行后获取数据并将其保存在变量数组中以供以后使用,“ArraySigMaMatrices()”是获取数据的方法之一。 我现在的问题是,有没有办法让这个过程更快

我的第二个问题是,在java中运行线程的速度与什么有关

当然,如果您看到代码中的某些内容可以以更好的方式完成,请随时通知我
谢谢

你应该像这样改变你的方法

public void arraysSigmaMatrices() throws FileNotFoundException, IOException {
    for(int catrgory = 0; catrgory < excelSheets.length; catrgory++) {
        try (FileInputStream input = new FileInputStream(excelSheets[catrgory])) {
            HSSFWorkbook workbook=new HSSFWorkbook(input);//to be able to create everything in the excel sheet
        }
        for(int ngauss = 0; ngauss < 30; ngauss++){
            String sheetname="Sigma"+(String.valueOf(ngauss+1));//adding the index to the sheet name
            HSSFSheet sheet=workbook.getSheet(sheetname);//getting the sheet
            for(int row= 0; row < 13; row++) {
                HSSFRow rows=sheet.getRow(row);
                for(int column= 0; column < 13; column++) {
                    arraysSigmaMatrices[catrgory][ngauss][row][column]=rows.getCell(column).getNumericCellValue();
                }
            }
        }           
    }
}
public void arraysSigmaMatrices()抛出FileNotFoundException、IOException{
对于(int-catrgory=0;catrgory

这将减少文件读取的次数,并节省资源。

您应该这样更改您的方法

public void arraysSigmaMatrices() throws FileNotFoundException, IOException {
    for(int catrgory = 0; catrgory < excelSheets.length; catrgory++) {
        try (FileInputStream input = new FileInputStream(excelSheets[catrgory])) {
            HSSFWorkbook workbook=new HSSFWorkbook(input);//to be able to create everything in the excel sheet
        }
        for(int ngauss = 0; ngauss < 30; ngauss++){
            String sheetname="Sigma"+(String.valueOf(ngauss+1));//adding the index to the sheet name
            HSSFSheet sheet=workbook.getSheet(sheetname);//getting the sheet
            for(int row= 0; row < 13; row++) {
                HSSFRow rows=sheet.getRow(row);
                for(int column= 0; column < 13; column++) {
                    arraysSigmaMatrices[catrgory][ngauss][row][column]=rows.getCell(column).getNumericCellValue();
                }
            }
        }           
    }
}
public void arraysSigmaMatrices()抛出FileNotFoundException、IOException{
对于(int-catrgory=0;catrgory

这将减少文件读取次数,并节省资源。

您是否尝试过将这些性能与进行比较?我正在使用Apache POI,是否应该尝试其他库?很抱歉,我没有看到它。不,我认为您应该继续使用此库,看看saka1029的回答您是否尝试过将这些性能与进行比较?我是using Apache POI,我应该尝试另一个库吗?很抱歉,我没有看到它。不,我认为你应该继续使用这个库,看看saka1029的回答谢谢你,我忘记了考虑流的开放,现在需要2秒钟谢谢你,我忘了考虑流的开放,现在需要2秒钟