08-26-2009 02:25 PM
My application creates many threads at various point of time.
Normally, in Nokia when application exits, it destroys all threads.
But I think BlackBerry doesn't. Thats because I am getting TooManyThreadsException if I exit software and start it again 5-6 times.
I wish to kill all threads on BlackBerry when my application exits.
At that time, threads might be waiting for some object, doing IO etc.
Please tell how to do this
Thanks in advance
08-26-2009 02:45 PM
Before exting the application stop all the runnung thread.
I mean something like:
thread1.stop(); thread2.stop(); ...
Regards
Bikas
08-26-2009 07:13 PM
But for that I have to keep track of all threads which are created.
Isn't there a single API to kill all threads?
08-26-2009 11:53 PM
If a thread is waiting on I/O (or deadlocked, or whatever) when you call exit(), I don't know what happens, but I'd guess that you're right--the thread just hangs around. The easiest way to end a waiting thread is to call interrupt(). If a thread is busy calculating pi to the last digit, it should be written to check a "please quit" variable somewhere that can be set externally. Unfortunately, there is no Thread.stop() method on BB.
Since there are no thread groups or daemon threads on BB devices, you might have to write your own thread manager to do all this. The manager would be told when threads are created, when they finish, and when the app is going to exit. For the last, it would go through the list of threads and calls interrupt() on each one that's still alive. This will work better if you write all your thread code to cooperate with the manager (for instance, to register itself with the manager and to notify it when the thread finishes).
If you have threads being spawned inside code you don't control, I don't have any good suggestions.
08-27-2009 04:07 AM - edited 08-27-2009 04:07 AM
08-27-2009 04:13 AM
08-27-2009 04:17 AM
08-27-2009 02:11 PM
I am not sure what is this concept of "background" threads in blackberry and its difference with normal threads but page 12 of this document says:
Multithreading
The BlackBerry® operating system is a multithreaded operating system, which means that many applications and processes can
run actively on the BlackBerry device at the same time. For example, applications can use background threads to manage
processor-intensive tasks or network communications so that they do not affect the main thread. If an application creates
background threads, and a BlackBerry device user closes the application, the background threads can remain active.
If all threads are automatically destroyed when application is exited then may you answer:
1. Why I get TooManyThreadsException if I start my application and close it around 5 times.
2. If I OTA install my application it gets installed successfully. Now if OTA install again, it asks for replacement and gets installed successfully without any reboot. But in between successive installation, if I start and exit application then next installation demands reboot. Why?
08-27-2009 03:21 PM
1. Check this KB article.
What Is - TooManyThreadsError
Also check this thread.
2 . Have a look at this KB article.
What Is - The reason a reset is required when upgrading an application
http://www.blackberry.com/knowledgecenterpublic/li
Regards
Bikas
08-30-2009 08:12 PM - edited 08-30-2009 08:13 PM
I have found that if I don't use PushRegistry then everything works fine.
But if I use:
String MIDletRegistered = PushRegistry.getMIDlet("sms://:16001");
String RegisteredConnections[] = PushRegistry.listConnections(false);
if(RegisteredConnections == null){
RegisteredConnections = new String[0];
}
if((MIDletRegistered == null) && (RegisteredConnections.length == 0)){
PushRegistry.registerConnection("sms://:16001", "MyApp1.MIDletClassMain", "*");
}
and then if I start application & close say 5 times then I get TooManyThreadsException
Why so???
Thanks in advance