Sunderam Goplalan wrote:I'd use Thread.sleep if there are, say 4 threads, and assume threads 1,2,3 hog the limelight for some reason. Suppose I want to give a chance for other thread 4 to run, I would use
Thread.sleep on Thread 1,2 3 so that output from Thread 4 is visible too.
You don't need to do that. Unless you have a very old or very unusual JVM implementation or underlying OS and hardware, those three will handle scheduling pretty well without any interference from you.
If you have measured and observed that some threads are being starved, you could try adjusting the various threads' relative priorities. As an absolute last resort, you might try calling Thread.yield(). Although, really, you shouldn't need to concern yourself with thread scheduling.