As my app matures, I find myself finding more and more uses for threads. By now I must have about 25 threads, all doing important things and working together in symphony.
I notice however that my app is sitting around 15.5MB resident. Compared to the browser (+/-35MB) I feel pretty safe, but I do notice the resident size of my app ever increasing.
The question is, how much overhead is involved with adding a thread?
I’m also wondering if the synchronized keyword encounters more and more latency with each new thread that is present?
Thanks!
Threads are very useful but at the same time they can be a menace. I am working on a project to check threats presented by an application. If you run top via the adb shell, it specifically tells you how many threads an application may be running.
You will see processor usage is directly proportional to the number of threads. That pretty much means more the number of threads higher is the overhead. Though they seem to keep your activity free from getting stuck at time it may become a real pain to synchronize their actions and then you may have deadlock, not very pretty. Also multiple no of threads raise suspicion about the behaviour of an application. Hence they should be utilized in the spirit they are meant to be.