Search code examples
androidforceclosethread-priority

In Android app setting current Thread priority to less than 1 causes a force close


I am trying to increase the priority of a thread in my application by putting:

Thread.currentThread().setPriority(N);

The normal priority of current thread is 5, I can change N to as low as 1, but if I put it to 0 or -1 I get a force close message on my phone.

Is there a reason I cannot increase the priority of this thread?


Solution

  • If you look at the documentation for Thread.setPriority(), it says the priority must be in a range defined by MAX_PRIORITY (10) and MIN_PRIORITY (1). Since 0 and -1 are outside that range you should be seeing an IllegalArgumentException.