Image for post
Image for post

Exploring Android Thread Priority

Anubhav Gupta
Aug 31, 2018 · 4 min read

Android Scheduling Basics

The Java runtime supports a very simple, deterministic scheduling algorithm known as fixed priority scheduling.

Nice values

nice values in Android are used as a measure of a thread’s priority. Threads with a higher nice value (i.e., lower priority, as in they are being “nice” to other threads in the system) will run less often than those with lower nice values

Cgroups

The thread control groups(cgroups) are Linux container that are used to manage the allocation of processor time for all threads in one container

Image for post
Image for post

Why we need to set thread priority?

The threads created by application by default have the same priority and cgroup membership as UI thread. As a result they compete on equal terms for processor allocation. Hence an application that creates a lot of background threads may reduce performance of UI thread.

Image for post
Image for post
Worker thread competing for resources with UI thread

Setting Thread Priorities

Now we know what are thread priorities and that they should be set correctly to ensure app responsiveness. Let’s look at how to set thread priority in Android.

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post


MindOrks

Our community publishes stories worth reading on Android…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store