4

I was talking to an interesting interviewee today, who insisted that the best way to improve the performance of our Java application was to rewrite the thread scheduling algorithm. Given that we rely on the JVM thread scheduling algorithm I'm reasonably sure this isn't possible, but I was wondering if there's any techniques you can use to affect the scheduling algorithm. Or if there is even a compelling reason to do so.

PS The application in question doesn't have any serious performance problems. The interviewee was just a bit keen.

2
  • Didn't you ask him why? And how? Commented Jul 27, 2010 at 12:57
  • 3
    I think the real answer is "don't hire this candidate." Commented Jul 27, 2010 at 14:51

2 Answers 2

5

He is talking through his hat. There is no Java thread scheduling algorithm. Threads are scheduled by the operating system, since at least 1999.

And even if there was, there is nowhere sensible that gives you the opportunity to rewrite it, short of implementing your own JVM.

Ask him how.

Sign up to request clarification or add additional context in comments.

3 Comments

+1 and amen to that... Probably a tiny bit later than 1999 on Linux. I don't remember exactly when the JVM switched to native Posix thread library but it was indeed many moons ago.
So a bit of research on POSIX thread libraries would probably be the most useful resource if you wanted to find out more about the scheduling algorithm? I assume that this isn't true if you're code is running on Windows?
No. A bit of research into the operating ayatem's support for threads. This hasn't been in a library for ten years or so. And it is most unlikely to help you with your application' perormance. The best bets for that are faster hardware, more memory, less contention, bigger buffers, etc as usual.
2

I quite certain that the Java Language Specification doesn't specify concretely how threads (that is, the threads in the RUNNABLE state) are scheduled. It probably requires some kind of fairness, but the details are most likely up to the JVM implementor to decide (which means that you don't have any more control over it than the JVM in question provides you with).

For efficiency reasons, most of them probably defer the task to the OS straight away.

I'll see if I can find some references.


You can "tweak" the scheduling of course, by for instance setting the priorities (from the docs on Thread: Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority.), or by synchronizing the threads using monitors.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.