06-06-2012 08:56 AM
My application screen looks similar to the image attached. I have multiple rows and each row has a Bitmap image, title and description field. All the information's are getting fetched from our supporting web-server in the form of XML. Now, I have used observer design pattern, which creates a separate thread for connecting to my remote server over HTTP, downloads and parse the XML. The XML includes the URL for image, title and description for each row.
I have tried few approaches so far,
- Created a separate method (drawRow()), which takes care of putting the contents together by specifying the layout.
- And, then using the method downloadImage(), I am trying to download the remote URL from the drawRow() method. But it sucks, as it downloads using the same thread and UI gets blocked.
- While searching for the above issue, I came across WebBitmapField in blackberry from coderholic.com.
- And, then I am using the below code from my drawRow() method. As I understand the WebBitmapField, here is using observer design pattern and the image is downloading over thread other than UI thread. It works fine when I have limited number of rows like 5 or 10. But when I have more number of rows to be drawn it throws TooManyThreads exception, as it creates a new thread for each row.
I have got this link taskworker-thread-blackberry, but not much clear with how to achieve my requirement.
As I understand, in blackberry an application can create maximum of 16 number of threads. So, now I believe. I may need to create a thread pool specifying max size to 10.
Can anyone please help me to understand and implement the thread pooling for blackberry for my current problem?
Also, I appreciate anyone giving me any other best approach which will fit for my requirement.
Thanks in advance.
06-06-2012 09:00 AM
06-06-2012 09:04 AM - edited 06-06-2012 09:05 AM
As I am a kind of newbie can you please explain how i can do it with list view?
Can call downloadImage() method from drawRow() method before drawing of each image? or how I should do this ?
06-06-2012 09:05 AM
The preferred approach is #2.
You would have to implement your own manager which would maintain a list of active threads and start new ones only when available (#activeThreads < MAX_NUM_OF_THREADS).
If you would search the forum, you will find few threads regarding this issue.
If you need assistant implementing the manager, post again with the code which you already wrote for it.
06-06-2012 09:09 AM
Hello @maadani, I truely appriciate for your quick reply. I am using the below link which explains creating of own manager. Can you please help me to understand how could I change it to fix for my requirement. I mean how could I create pooling mechanism ?
06-06-2012 09:16 AM
06-06-2012 09:26 AM - edited 06-06-2012 09:28 AM
Here is a good example to to write a ListField, as mentioned by Simon:
Now, the link that you gave is only for one field and you would need a manager that would maintain a list (or a runnable queue).
Here is a link for a thread pool:
IMPORTANT NOTE: not specifically for BB but it will get you started...
Do note that you would need to pass a callback object to your manager that would be called once the download is done.