Do themes add a lot of overhead to the app?

When my application matures, I find that more and more is used for threads. By now, I should have about 25 threads, they all do important things and work together in a symphony.

I noticed that my application sits around 15.5 MB. Compared to the browser (+/- 35 MB), I feel pretty confident, but I notice that the size of my resident application is increasing.

The question is how much overhead is associated with adding a stream?

I am also wondering if the synchronized keyword meets more and more latency with every new thread that is present?

Thanks!

+6
java android multithreading
source share
4 answers

Themes are very useful, but at the same time they can be a threat. I am working on a project to test the threats posed by the application. If you run the vertex through the adb shell, it specifically indicates how many threads the application will execute.

You will see that processor utilization is directly proportional to the number of threads. This largely means that the number of threads higher is overhead. Although they do not seem to allow your activities to get stuck in time on time, it can be a real pain to synchronize your actions, and then you can have a dead end, and not very pretty. Also, several threads of threads cause suspicion about the behavior of the application. Therefore, they should be used in the spirit that they should be.

+2
source share

For some perspective, here, the recently launched Browser application has about 20 threads. The presence of 25 threads is not completely unreasonable. It really depends on what you do with them.

 app_1 17309 67 182452 27944 ffffffff 00000000 S com.android.browser app_1 17310 17309 182452 27944 ffffffff 00000000 S HeapWorker app_1 17311 17309 182452 27944 ffffffff 00000000 S Signal Catcher app_1 17312 17309 182452 27944 ffffffff 00000000 S JDWP app_1 17313 17309 182452 27944 ffffffff 00000000 S Compiler app_1 17314 17309 182452 27944 ffffffff 00000000 S Binder Thread # app_1 17315 17309 182452 27944 ffffffff 00000000 S Binder Thread # app_1 17317 17309 182452 27944 ffffffff 00000000 S CookieSyncManag app_1 17319 17309 182452 27944 ffffffff 00000000 S WebViewCoreThre app_1 17321 17309 182452 27944 ffffffff 00000000 S AsyncTask #1 app_1 17322 17309 182452 27944 ffffffff 00000000 S AsyncTask #2 app_1 17323 17309 182452 27944 ffffffff 00000000 S WebViewCoreThre app_1 17324 17309 182452 27944 ffffffff 00000000 S http0 app_1 17325 17309 182452 27944 ffffffff 00000000 S http1 app_1 17326 17309 182452 27944 ffffffff 00000000 S http2 app_1 17327 17309 182452 27944 ffffffff 00000000 S http3 app_1 17328 17309 182452 27944 ffffffff 00000000 S WebViewWorkerTh app_1 17329 17309 182452 27944 ffffffff 00000000 S AsyncTask #3 app_1 17330 17309 182452 27944 ffffffff 00000000 S AsyncTask #4 app_1 17332 17309 182452 27944 ffffffff 00000000 S AsyncTask #5 
+3
source share

If you create and destroy flows over and over, then yes, it will tax and impose overheads. You can fix this using ThreadPool, which keeps the thread cache available for execution. Otherwise, threads are a way to go to processes.

You may think about practical architecture adjustments. For example, if you keep several streams alive for the sake of having an adaptive user interface (i.e., Wait for input), even if a particular stream will be used only after five menu transitions, then it may not be necessary to keep streams alive all the time. I rarely used 15 separate threads in a single application, even when this application ran a massive machine tool .... (I had repeated worker threads). Remember that threads still need to be scheduled, so you don’t need them uselessly.

Finally, make sure you are not facing the same old problems with a parallel program; avoid deadlocks, etc.

+2
source share

An uncontrolled number of threads can be overhead for the application. Your APP already has more streams for the mobile application.

synchronized, requires maintenance to lock objects.

Checkout if you can use ThreadPoolExecutor. This will help limit threads in the system, as well as reduce the small overhead of creating and destroying threads.

0
source share

All Articles