Welcome!

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

Reply
Developer
Iyenemi_Tyger
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
Accepted Solution

HttpConnection maximum no of connections exceeded

hello and good day ,

 

Please what is the most efficient way to manage http connections in a case where for example i need to load people data and display like this :

 

picture              name

--------------    --------------------------

 

picture              name

---------------  ----------------------------

 

now i will need to display @ least 200 + of this , so i first of all downloaded all the names , and then created a threadpool to manage the download of images , i have an exception when downloading more than 20 images when making a httpconnection is there a way to pool the httpconnection knowing that the url of the image is different for each row , i really need to know , thanks .

Please use plain text.
Developer
simon_hain
Posts: 16,216
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: HttpConnection maximum no of connections exceeded

the OS cannot manage more than a few connections at a time anyhow, so using more than these few makes no sense.
ensure that you close a connection properly and you should be able to open a new one after that.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
Iyenemi_Tyger
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630

Re: HttpConnection maximum no of connections exceeded

Thanks simon , that's the problem my connections are properly closed after each image is fetched and that is when the error pops up , what I am asking is how do I optimize the connection process so it won't try to create a new connection for each row of photo is there any pattern or technic ? , I am testing using one global connection object for the class and once the screen is closed I terminate the connection but its danm slow to fetch images
Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: HttpConnection maximum no of connections exceeded

There are a number of Threads on the forum that discuss this.  This is not too bad:

 

http://supportforums.blackberry.com/t5/Java-Development/Getting-Too-many-Threads-problem-while-dowlo...

 

but I think there are a number of others.  Have a search round. 

 

A single queue and a single Thread downloading is a simple solution to implement usually.  but Mutliple Threads will probably see better performance, the debate is how many, and I think that depends on the OS and the connection method. 

Please use plain text.
Developer
simon_hain
Posts: 16,216
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: HttpConnection maximum no of connections exceeded

we use three threads in a command queue where we just throw runnables in (with a callback for the result).
we modified the number a few times, but 3 seemed the best (without any real analysis, as this was not that important)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
Iyenemi_Tyger
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630

Sample ThreadPool implementation

Thanks everyone , Please can anyone lead me to a proper sample thread pool implementation for blackberry , thanks.

Please use plain text.
Developer
simon_hain
Posts: 16,216
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Sample ThreadPool implementation

i am not aware of any.
our approach uses a notify object (notify/wait) and a queue, with three worker threads that sleep unless notified.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
Iyenemi_Tyger
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630

Re: Sample ThreadPool implementation

Thanks simon please can i see your sample code so i can understand how to implement mine i am talking of a system wide threadpool impementation that will enable tasks to be accomplished in a queue if there are no tasks they all sleep.

Please use plain text.