03-09-2013 03:00 PM
I made a simple application in which I am running multiple threads. But mostly some thread get stuck means they do not execute. Can anyone suggest what could be solution for this.
03-09-2013 06:43 PM
I am not aware of the OS stopping Threads that are working.
So I guess the reason they stop, is something in the application or the environment. For example, if the device goes to sleep, then any background Thread that does networking will probably fail. The best thing I think you can do is put logging into your Threads, make sure you have appropriate try/catch clauses and then review the log when the unexpected happens.
03-10-2013 06:56 AM
The network operation was just an example, Another example is accessing persistent store, which might fail when the device is locked. It all depends on what your Thread does.
For the Thread to stop, it seems most likely that there was a failure in the processing. So what was that failure? I suggest you put appropriate logging and try/catch code and find out!
Please don't post your code and ask us to debug it.
03-10-2013 09:05 AM - edited 03-10-2013 09:41 AM
"There is no problem in code."
Are you sure? If there was no problem in the code, why does it stop?
As noted, you have some Threads that carry on, and this one Thread that stops. There is nothing in the OS that will automatically stop Threads. So it seems the most logical conclusion that can be drawn is that there is something in your code that results in it stopping. Can you give any other explanation?
"Thread are running fine when i test application in simulator"
Next time give us this sort of information right up front. It would have been useful to know it was a networking Thread too. The more information you give us, the more specific our answers will be. See this Thread which is a sticky Thread right at the top of the list....:
As you should be aware, a Simulator and the device are not the same thing. The differences that normally catch people out are:
1) there are normally no Application Permissions required on the Simulator.
2) network processing is very quick, which means that using the Simulator you can get away with doing network processing on the Event Thread.
3) Network processing doesn't suffer from the problems caused by wireless connections, like connection limits or transcoders changing your wireless communications.
4) Long running processing can run on the Event Thread because the PC is so fast.
5) Different levels of OS on Simulator and device cause subtle differences in the processing, for example the order in which asynchronous events happen.
These are only the most common examples, there are other differences.
With the information we have, we can't even guess what the problem is.
I think the following comment from my first post still applies.
"The best thing I think you can do is put logging into your Threads, make sure you have appropriate try/catch clauses and then review the log when the unexpected happens."