BlackBerry Forums Support Community               

Closed Thread
LinkBack Thread Tools
Old 03-22-2009, 05:59 AM   #1 (permalink)
New Member
Join Date: Sep 2008
Model: 8100
Carrier: AT&T
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Too many Threads Uncaught Exception

Please Login to Remove!

Hi ,
We are having an application in which we are frequently getting the uncaught exception of TooManyThreadsException.
Can any one tell how many maximum threads are supported in a Blackberry Device.
Or how can we fix this issue ?
Old 03-22-2009, 02:06 PM   #2 (permalink)
Thumbs Must Hurt
Join Date: Nov 2008
Location: Sioux Falls, SD
Model: 9530
Carrier: Verizon Wireless
Posts: 65
Post Thanks: 0
Thanked 0 Times in 0 Posts

A simple Google search reveals:

BTW - The answer is 16.
Handspring >> Palm >> BB Pearl >> BB Storm

Old 03-23-2009, 01:04 AM   #3 (permalink)
Knows Where the Search Button Is
Join Date: Feb 2009
Model: 9000
Carrier: AT&T
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts

Rather than spinning off threads for each and every task its recommended that you implement the work queue pattern. Its quite a simple idea, where you spin up a thread which sits around waiting on a semaphore to be posted to. Once the sema gets a post the thread goes and pulls an item out of the top of a vector and invokes execute() on it.
You can obviously implement this with a pool of worker threads waiting on the semaphore.
In your application code rather than creating new threads, you simply construct new WorkItem objects that implement the work item interface:
interface WorkItem {
void execute();
And add them to your work queue. The add method for your work queue should add the item to the Vector and post to the semaphore (releasing a thread to work on this item if its free). This isn't terribly different to spinning up a new thread from a coding perspective your just switching out 'extends Thread' with 'implements WorkItem' and renaming run as execute. This is of course once you've implemented the work queue classes/infrastructure.
Old 03-23-2009, 05:07 AM   #4 (permalink)
CrackBerry Addict
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts

don't forget to synchronize the vector access, the j2me vector class is not synchronized per se.
work queues are indeed a good solution, you can also use a thread factory.
java developer, Devinto, hamburg/germany
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Copyright 2004-2014
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.