Originally posted by Louis:
It seems when one thread runs out its time slicing, the OS will let other threads get to run. Why I need bother to invoke Thread.sleep() method to transfer the CPU time to other threads?
hi,
While developing mulithreaded application, developer should not consider what mechanism OS follow, time slicing, preemptive, no preemptive or whatever. How can we be assured that what time slicing the CPU has given to particular thread. So therfore we programatically do Thread.sleep(1000) or so, that we could be assured that while thread executes this line, it sleeps. One more thing, if a thread sleeps it does not leave the object so that lock or synchronized code can't be accessed by another thread while the prior one is sleeping.
Thanks and Regards,
cmbhatt