简体   繁体   中英

Executing long-running task from Tapestry using already existing EJB service

I have the following situation.

I have my web site written in Tapestry. On one of the pages, I'm required to generate a fairly large Excel or PDF document (around 20 MB). Now, since the entire process takes time, I'm asking my user to wait a bit.

However, when I tried to test the upper limits, I noticed that my entire application (not just the web part) freezes, because the generation eats up all the resources and the rest of the website and application becomes unresponsive.

Here is the flow how I've been doing it so far.

  1. User clicks a button to request the file on the page
  2. Data is being fetched from database (this part is quite fast)
  3. Data is passed to a Tapestry service which prepares it (nothing fancy, also fast)
  4. Prepared data is sent to EJB service which creates and deploys a visitor which creates the excel/pdf file
  5. The InputStream of the created file is passed all the way up to Tapestry which wraps it in StreamResponse and offers the download

What would be an appropriate way to handle this problem?

Could I perhaps use Tapestry's ParallelExecutor from some Tapestry service of mine in a manner like this?

Future<InputStream> future = executor.invoke(new Invokable<InputStream>() { ... });

My main objective is that the application and website keep running, that they do not freeze.

Thank you in advance.

Take a look at the progresslink demo from tapestry stitch. It might give you some inspiration to poll for a long running / asynchronous task in tapestry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM