[java] concurrency question

Started by
1 comment, last by ahung89 15 years, 3 months ago
Hey all. I've started a new book - "Killer Java Game Programming." I've been reading the first chapter which talks about the animation framework. There's one concept that I'm confused about. I just recently learned about concurrency and what I understand is that threads are different processes that are running simultaneously. But one of the features of the code in the animation framework, as stated by the author, has "Thread.yield() utilized to give other threads a chance to execute if the animation loop has not slept for a while." Why would it have to yield if the other threads are already running at the same time? Doesn't make any sense to me. I'd really appreciate if someone could clarify this for me.
Advertisement
Threads represent multiple processes but they still run in a sequential order like multiple OS threads on a single core machine.

A Thread does not necessarily run to completion but might be given a time slice to execute, is paused/suspended while another Thread is running and be resumed again. If you call Thread.yield() you can suspend the thread yourself in order to give the JVM a hint that it should resume another thread. The JVM may, however, choose to resume the same thread, since that's not defined in the specification.

Hope that makes it clearer a bit.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Thanks. That makes perfect sense.

This topic is closed to new replies.

Advertisement