Re: How to run tasks with priority?



"George George via JavaKB.com" <forum@xxxxxxxxxx> schreef in bericht
news:c5f97c90dab54524b5b6b298c37ed849@xxxxxxxxxxxxx
> Thanks Boudewijn,
>
>
> Boudewijn Dijkstra wrote:
>>> Thanks Boudewijn,
>>>
>>[quoted text clipped - 8 lines]
>>> make current thread idle on CPU (current thread will not occupy CPU time)
>>> and it will give chances to other threads to run on CPU. Am I correct?
>>
>>That is correct. But yield will have no effect if the current thread is the
>>only 'ready' one with the same priority.
>>
>
> Your reply is very helpful! I am wondering how can I write a simple program
> to verify that the difference behavior of yield method and sleep method. Do
> you have any good ideas?

Make a thread that increments a variable as fast as it can. After every
increment it calls an abstract myWait() method that waits a number of
milliseconds. One implementation loops yield() until it reaches the wait
time. The other implementation simply calls sleep(long).


.