Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

New Contributor
Posts: 8
Registered: ‎07-14-2010
My Device: Tour - 9630
My Carrier: Verizon

Best way to open Multiple HTTP connections

I've looked around the forums and haven't found the best way to do what I'm interested in.  I'm writing an application that requires downloading multiple images and then composing them on top of each other to produce the final image.  I'm wondering if the best way to do this is to open multiple connection threads and then try to .join() all of them all at the end, or if I should open and close each connection serialy, one after another?  None of the files are appreciably larger than the others, so each one should take approximately the same time to download. 

Regular Contributor
Posts: 71
Registered: ‎07-11-2010
My Device: Bold 9000
My Carrier: none

Re: Best way to open Multiple HTTP connections

Usually I'd go with the simplest approach - download images one after another.

  • this will greatly decrease the complexity of the code and especially error handling 
  • it will allow you to easily display progress bar 
  • if there is error while downloading some of the images, you can redownload only it
  • there is probably restriction on number of concurrent connections, this way you won't have to fight with strange errors caused by this restriction

The only advantage to use parallel download is if you are working with large data sets and you believe that parallel download will improve the speed. (Which I do not think is the case).



Note - for each image download, start a I/O thread PLUS some tracking mechanism (TimerTask or another thread). If there is no data coming for 10-15 seconds, you should kill the connection and start again.

A good decision is based on knowledge and not on numbers.