Jump to content
  • Advertisement
Sign in to follow this  
ahung89

[java] concurrency question

This topic is 3563 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!