Re: How to run tasks with priority?



"George George via JavaKB.com" <forum@xxxxxxxxxx> schreef in bericht
news:1b0ed44698de4e4fb399a8187c1e13e0@xxxxxxxxxxxxx
> Thanks Boudewijn,
>
>
> Your sample is very helpful. But I think there is an issue in your sample,
> which is that we must hardcode the number of sections that a code block
> will be divided into. For example, in your sample, you hardcoded that Task1
> is divided into 3 sections. I am wondering whether there are any approaches
> 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--;
}
}

> 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.

> Should we do it in this approach (yield)
> manually or simply let JVM to do this.

That is a decision that I cannot make for you. ;)


.



Relevant Pages

  • Re: How to find the Column Index By Name in an ASP.Net DataGrid
    ... If the columns are not auto-generated, you can use datagrid Columns ... Write a utility function that will take a column name as a ... parameter, loop through Columns collection, find a column with matching ... > I don't want to hardcode the column number 16 in the above example. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Do While loop syntax
    ... The while loop is fine to test a real value. ... I would had imagine that the compiler could easily ... code block with the while statement above it? ... That's why the semi-colon is needed. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Checking the value of recv()
    ... Marc Rochkind wrote: ... > It looks to me that that code block is inside the loop, ... > executed in the equals-zero case. ...
    (comp.unix.programmer)
  • Re: For If Next problem
    ... Exit For will jump out of the entire loop. ... Private Sub Command1_Click ... Dim i As Integer ...
    (microsoft.public.vb.syntax)
  • Re: Checking the value of recv()
    ... Marc Rochkind wrote: ... > It looks to me that that code block is inside the loop, ... > executed in the equals-zero case. ...
    (comp.os.linux.development.apps)