I am facing problem in blackberry development. In my application I have to get images from the server, so i have to create a separate connection thread for each image i load from the server..but in doing so i am getting TooManyThreadsException..Any ideas regarding controlling the threads...
In blackberry an application can have maximum of 16 threads running concurrently...but i have to display more than 16 images at a time...
Reuse the threads, queue up all the images, and run just a couple of threads, each processing one image at a time and then moving on to the next.
There is a reason the unit only allows 16 per process, and it has to do with resources. You basically have to make do with fewer threads.
You run into a similar limitation with older browsers like IE6 which limit you to 2 concurrent connections per domain.
Re-use the threads and download the images serially on fewer concurrent threads (perhaps using 2-3 threads to speed things up).
Just speculating here, but tying up all 16 threads seems like it could lead to an unstable environment since the BB OS is doing other things while your program is running.
I have been taught that creating threads dynamically is almost never an good approach, I would have created 1-2 worker threads with an queue that would do the job for me.
来源:https://stackoverflow.com/questions/1410990/too-many-threads-exception