Re: How to run tasks with priority?



Thanks Boudewijn,


Boudewijn Dijkstra wrote:
>> Thanks Boudewijn,
>>
>[quoted text clipped - 4 lines]
>> which can flexibly define the number of sections in which a thread will be
>> divided into.
>
>You don't actually have to define your code into sections. It should even be
>possible to change the number of synchronized accesses dynamically, by using a
>loop inside your main loop:
>
>for (int i = syncCount; i >= 0; ) {
> synchronized (lock) {
> i--;
> }
>}

Do you mean that when the current thread leaves a synchronized block, it
will release the lock and then other threads will have chances to obtain
the lock?

>> Are there any practical uses that we should give away it's cycle to other
>> threads with the same priority?
>
>Yes. You can use it in a lot of cases when you're using the sleep method, but
>without the chance of actually idleing the CPU.

Do you mean using yield method will idle the CPU? If it is true, do you
know how to write a simple program to test that sleep method will not idle
CPU, and at the same time yield method will idle CPU?


Have a nice weekend,
George

--
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200506/1
.



Relevant Pages

  • Re: How to run tasks with priority?
    ... > Boudewijn Dijkstra wrote: ... >>> Do you mean using yield method will idle the CPU? ...
    (comp.lang.java.help)
  • Re: How to run tasks with priority?
    ... Boudewijn Dijkstra wrote: ... >> make current thread idle on CPU ... >> and it will give chances to other threads to run on CPU. ... to verify that the difference behavior of yield method and sleep method. ...
    (comp.lang.java.help)
  • Re: Alternate for Sleep Method in VB Script
    ... script at certain points. ... Sleep method does not work and if I use a ... Looking if somebody has a solution for this without using a CPU ... intensive loop. ...
    (microsoft.public.dotnet.languages.vb)