我从数据库中获取 26000 条记录并列入列表,同时将该列表导出为PDF或excel需要花费太多时间。
report.toXlsx(new FileOutputStream(fileForXls));
以上行需要30到40秒才能执行。 如何缩短执行时间?
代码
public synchronized String execute(){
JasperReportBuilder report = DynamicReports.report();//a new report
StyleBuilder boldStyle = DynamicReports.stl.style().bold();
StyleBuilder boldCenteredStyle = DynamicReports.stl.style(boldStyle)
.setHorizontalAlignment(HorizontalAlignment.CENTER);
StyleBuilder columnTitleStyle = DynamicReports.stl.style(boldCenteredStyle)
.setBorder(DynamicReports.stl.pen1Point())
.setBackgroundColor(Color.LIGHT_GRAY);
report
.columns(
Columns.column("Sr #", "srNumber",DataTypes.integerType()).setWidth(40).setHorizontalAlignment(HorizontalAlignment.LEFT),
Columns.column("IR No", "irNo", DataTypes.stringType()).setWidth(130),
Columns.column("Status", "state", DataTypes.stringType()));
report.columnGrid()
.setIgnorePageWidth(true)
.title( // title of the report
Components
.text("IR Report")
.setStyle(boldCenteredStyle)
.setHorizontalAlignment(
HorizontalAlignment.CENTER))
.setColumnTitleStyle(columnTitleStyle)
.highlightDetailEvenRows()
.pageFooter(
Components.pageXofY().setStyle(
boldCenteredStyle))
.setDataSource(createDataSource());
String fileForXls="D:/IRReport.xlsx";
report.toXlsx(new FileOutputStream(fileForXls)); //time consuming code
return SUCCESS;
}
private JRDataSource createDataSource() {
DRDataSource dataSource = new DRDataSource("srNumber","irNo", "state");
List<ResultHeaderBean> data1= irdao.getAllRecords(); //returns List of 26000 records
int count=0;
for(ResultHeaderBean data:data1 ){
count=++count;
dataSource.add(count,crdata.getIrNumber(), crdata.getStatus());
}
return dataSource;
}