BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-22-2009, 04:59 AM   #1 (permalink)
New Member
 
Join Date: Sep 2008
Model: 8100
PIN: N/A
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 ?
Offline  
Old 03-22-2009, 01:06 PM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Nov 2008
Location: Sioux Falls, SD
Model: 9530
PIN: N/A
Carrier: Verizon Wireless
Posts: 65
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

A simple Google search reveals:

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

Tumblog: http://www.geekkink.com
Blog: http://www.zechariahs.org/blog
Offline  
Old 03-23-2009, 12:04 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Feb 2009
Model: 9000
PIN: N/A
Carrier: AT&T
Posts: 16
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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:
Code:
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.
Offline  
Old 03-23-2009, 04: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
Default

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
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.