View Single Post
  #13   Spotlight this post!  
Unread 08-01-2014, 12:10
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,101
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How to make timed sequences in java?

Quote:
Originally Posted by omalleyj View Post
Hard to say without looking in detail. You have the constant tests for setting and checking vs. the context switch to handle the thread.
Your "polling" code (a form of state machine as shown) runs once every 20ms yes? While you're waiting for the 2 seconds to elapse, you're doing one simple conditional jump every 20ms.

If CPU usage becomes a problem using this approach, there's probably something seriously wrong elsewhere in the code.