views:

365

answers:

2

I understand that if you specify thread priorities other than the default in Java then it makes the program platform specific. If you were to create threads for an android application and modify the priorities then would the app platform specific across different android versions (i.e. Cupcake/Donut and modified versions of Android like HTC's Sense UI etc.)? Thanks.

+3  A: 

I understand that if you specify thread priorities other than the default in Java then it makes the program platform specific.

I think that statement tends to be applied when the operating system or JVM changes.

If you were to create threads for an android application and modify the priorities then would the app platform specific across different android versions (i.e. Cupcake/Donut and modified versions of Android like HTC's Sense UI etc.)?

That is impossible to state conclusively, since you are asking us to predict the future.

That being said, Android's own Java code uses thread priorities, so if you stick to patterns you see in Android's code, odds are those patterns will continue to work. That being said, in Android as in life, there are no guarantees.

CommonsWare
+1  A: 

If you are simply worried about the range of thread priority values, it should be possible to write your code to be platform independent. Simply write some code that dynamically maps your application's logical priorities into the set of priority values that is available on the current platform.

But I suspect that you are worried that the you won't get consistent scheduler behaviour across different platforms. And yes, you are correct to worry. But the answer is to code your application so that this does not matter. For example:

  • Don't try to do your own scheduling by adjusting thread priorities up and down on the fly.
  • Beware of "priority inversion" where a higher priority thread has to wait for a lower priority thread to finish a task, release a lock, etc.
Stephen C