In fact, unless you are using a JVM that uses "green threads", it is the operating system that ultimately does thread time-slicing and thread scheduling. If you need to modify the scheduling, etc behaviour, start by looking at the facilities for doing this provided by your operating system.
One way I thought about is to write my own round robin scheduler and run it as a thread at a high priority level, and have it control all other threads. Would that work?
There are no guarantees. It depends on how responsive the OS'es thread scheduler is to changes in thread priorities.
Other problems with this approach (adjusting thread priorities) are:
- this will inevitably make your application more platform specific with respect to the interactions between your scheduler and the real (black box) thread scheduler,
- it will be really hard to know if your scheduler is working effectively, and
- it will make tracking down "heisenbugs" in your application harder.
Why do you think that it is necessary to do this?