Re: Inconsistent CPU usage
- From: Christian <fakemail@xxxxxx>
- Date: Wed, 30 Apr 2008 01:52:55 +0200
Elliot schrieb:
while(!pW.isFinished){;}; // programmatic block to put up screen
Its no longer DOS you have Threads .. and you have several of them also your OS might want some CPU power so its allways good to not use all at least not for waiting.
If you want execution to just yield and wait for something best approach would be to use wait()
use synchronize to get the monitor of an object then you can wait on it.
I would recommend you to exchange
while(!pW.isFinished){;};
with somthing like a call to a wait for finish method that could block until finished (though call back might most times be better.. depends..)
the lazy method to fix your code would be sth like:
while(!pW.isFinished()) {
Thread.sleep(100);
};
if the finished variable is volatile or synchronized by some other means this will work.
sun might have a learning trail for this.. GIYF
.
- Follow-Ups:
- Re: Inconsistent CPU usage
- From: Elliot
- Re: Inconsistent CPU usage
- References:
- Inconsistent CPU usage
- From: Elliot
- Inconsistent CPU usage
- Prev by Date: Recommendation on Performance Monitoring Software
- Next by Date: I have a problem for my return in the output
- Previous by thread: Re: Inconsistent CPU usage
- Next by thread: Re: Inconsistent CPU usage
- Index(es):