Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

downloading a huge file

 
pendse anagha
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,
I have a search screen - where user enters a number of parameters and based on these inputs - system searches the database tables and gets the results

System then generates a csv file and this is returned to the user

The entrie activity is synchronous .

The problem is - in the tables there are practically millions of records
so application just sits till results are returned

This could take loads of time - which is not desirable

Can someone suggest a asynchronous approach

I was thinking of this approach - where asynchronously some kind of scheduler processes the data and then sends across a link via email

However - the problem is - the user will then have to again authenticate
himself

I do not want the user to again authenticate

( I am not using cokkies for authentication - using HttpSession )

Your suggestions are most welcome

Thanks in advance.
-anagha
 
Robert Watkins
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Easiest way I can think of, if all you care about is giving the user some feedback, is to do the download in a seperate thread.

Once the downloading is in a seperate thread, you can attach a progress bar of some sort to it. Read the contents of the file in some not-too-large chunks (say, 10KB at a time) - on receiving each chunk, update the progress bar, and write the chunk to the destination file.

If you can find out in advance how large the file you're going to download is (even approximately) you can use this information to tailor the progress bar.

Note that you can also give the progress bar a cancel option - this would simply tell the downloading thread to abort.

Last, but no least - if the progress bar is not a modal window, the user can continue to work in the application while the download occurs.

Okay, all that assumed you were in a GUI application... if you're in a web based application, you can still do the progress bar, and the seperate thread work - simply place the spawned thread inside the user's session. However, if the file is truly big, you'll want to do it all synchronously anyway - the last thing you want is to have your server holding large files in memory all the time.

Finally - if avoiding authentication is all you care about, send the user an email with a one-off random token - say, about 200 characters long. This could then be used to retrieve the file without authentication with a some degree of security (based on obscurity). Naturally, you'd want the tokens to only be valid for a limited period of time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic