When Android Studio builds my project, it easily eats up all my 8 cores. I'd like to be able to fluently browse the internet while my app is compiling. Is there a way I can set Gradle's java processes to have a low priority (nice level > 10)?
That solution works perfectly for my gentoo system (with portage running on niceness 19 I can normally use my PC while it's compiling). Optimally, only Gradle's java should run at low priority, so Android Studio itself remains responsive. If that's not possible, maybe is it easier to limit Gradle's java VMs to use only 5-7 cores? It would probably result in longer build times though.
I experimented with this manually for a bit. I ran a script in a loop that sets nice level 15 ("priority low" for the windows users) for all new java processes every second. Unfortunately, the system is still not very responsive. I see that during compilation my average load goes up to twenty where I have only 4 (logical) cores. This means that Gradle spawns way too many threads. Somewhere else I read that also these threads rarely yield, which may be the cause why lowering priority doesn't help.
So, updated question is: is it possible to limit the number of threads used by Gradle?