Re: How to run tasks with priority?
- From: blmblm@xxxxxxxxxxxxx
- Date: 6 Jun 2005 05:56:38 GMT
In article <42a08662$0$1335$5fc3050@xxxxxxxxxxxxxxxxxxxxxxxx>,
Boudewijn Dijkstra <usenet@xxxxxxxxxxxxxxxxxxx> wrote:
>"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. ;)
Doesn't it depend to some extent on whether the JVM implementation
tries to do timeslicing if there's more than one thread with
the same priority? As far as I know, some do and some don't.
Then again, it's probably best to write in a way that will work for
any standard-conforming implementation ....
(And -- clever idea. My initial reaction was that it wasn't going to
be possible to do what the OP wanted without a lot more knowledge of
exactly how long various parts of his code took and/or of how the
JVM schedules threads. But after thinking more -- yeah, I think
what you're proposing might actually work, though I wonder whether
there isn't some strange way a JVM could do scheduling that would
defeat your scheme.)
--
| B. L. Massingill
| ObDisclaimer: I don't speak for my employers; they return the favor.
.
- Follow-Ups:
- Re: How to run tasks with priority?
- From: George George via JavaKB.com
- Re: How to run tasks with priority?
- References:
- Re: How to run tasks with priority?
- From: Boudewijn Dijkstra
- Re: How to run tasks with priority?
- From: George George via JavaKB.com
- Re: How to run tasks with priority?
- From: Boudewijn Dijkstra
- Re: How to run tasks with priority?
- Prev by Date: Re: How to run tasks with priority?
- Next by Date: Re: What's wrong with this generic type?!
- Previous by thread: Re: How to run tasks with priority?
- Next by thread: Re: How to run tasks with priority?
- Index(es):
Relevant Pages
|