Prioritization of threads within threads
concurrency, java, multithreading
Solution
Does `a` receive half of the available "attention" while `b` and its threads share the other half, or do they all share equally?
Neither. The proportion of time received by each thread is unspecified, and there's no reliable way to control it in Java. It is up to the native thread scheduler.
If the answer is the latter by default, how could you achieve the former?
You can't, reliably.
The only thing that you have to influence the relative amounts of time each thread gets to run are thread priorities. Even they are not reliable or predictable. The javadocs simply say that a high priority thread is executed "in preference to" a lower priority thread. In practice, it depends on how the native thread scheduler handles priorities.
For more details: http://docs.oracle.com/javase/7/docs/technotes/guides/vm/thread-priorities.html ... which includes information on how thread priorities on a range of platforms and Java versions.
Problem
Suppose you have a program that starts two threads `a` and `b`, and `b` starts another ten threads of its own. Does `a` receive half of the available "attention" while `b` and its threads share the other half, or do they all share equally? If the answer is the latter by default, how could you achieve the former? Thanks!