Download poor performance

Hi,

In my webapp, the user can generate and download a report. This happens when the user presses download, and unfortuanly when creating the streamsource, the whole webapp hangs, and I just can’t figure out why. Since the operation of generating the report can take up to 30 seconds to generate, I’m not the most popular man at the minute! :wink:

Whenever the user chooses to see testresults, the following button is made:

private Button createExportButton(String caption, String filename, StreamSource ss)
{
    Button b = new Button(caption);
    FileDownloader downloader = new FileDownloader(new StreamResource(ss, filename));
    downloader.extend(b);
    return b;
}

And the StreamSource is as following:

private StreamSource createPdfStreamSource() { return new StreamSource() { @Override public InputStream getStream() { List<Chart> allCHarts = new ArrayList<>(); List<testSpecifics> linecspecs = new ArrayList<>(); for(com.vaadin.ui.Component component : graphLayout){ try{ Chart chart = (Chart)component; allCHarts.add(chart); } catch(Exception e) {// I know - sry} } try { return new FileInputStream(new ResultPdfRGenerator().makePdf(allCHarts, currentSpecs, conctest, (Test)testChooser.getValue())); } catch (FileNotFoundException e) { e.printStackTrace(); } return null; } }; } Can any of you point me in the right direction, for
not
making this block the UI? The pdfGenerator is the slow thing here. I really hope you can help me here :slight_smile:

I guess I could create the report in the background such that it is ready for the user, but it’s only about 10% of the time, that the user actually needs the report, so I don’t think that will be a good idea.

Anyway, I’m keeping my fingers crossed!

Have a great week guys.

Best regards

Ben

A solution could be having a button “Generate report” that only starts the generation in a background thread (and disables itself) so the UI is not blocked; when the generation is completed add a new Link or Button “Download report” extended with FileDownloader.

This is not an optimal solution because it requires the user to click to times to download but it should work.

HTH
Marco

Dear Marco

Thank you for your reply.
This solution works as you proposed. It’s still better for the user to click twice, than to block the UI thread!

Thank you.
Benjamin