Re: [Jcyclone-users] Question on TPSScheduler
Brought to you by:
jm7
|
From: Quartz <qua...@ya...> - 2007-04-26 14:32:31
|
--- Fabien Gaud <fab...@fr...> wrote:
> Hello,
> I'm trying to understand how the scheduler works.
>
> I don't understand the procedure call Thread.yield() in TPSScheduler. I
> first believed that it was useless, but when I tried to remove this
> call, performance became bad.
> Does someone can explain me the purpose of this call? I don't understand
> why we should insert yield points.
------- simplified while(true) body ---------------------
Thread.yield();
while ((batch = sorter.nextBatch(blockTime)) != null) {
List events = batch.getBatch();
handler.handleEvents(events);
batch.batchDone();
}
---------------------------------------------------------
If somehow the sorter.nextBatch(blockTime) call isn't blocking, the thread
would loop at full speed, unfairly taking all CPU unless the OS kernel context switches it by
force, much later.
Using yield creates an opportunity for the kernel to perform the context switch. It is like
calling sleep() but without delay. But this is bad programming (relies on kernel scheduling). The
sorter.nextBatch() should wait() for events when there is none and context switching should occur
naturally. Make sure the nextBatch() is blocking when empty. If not, your loss of performance when
not using yield() is obvious. Watch your cpu usage too. It shouldn't be 100% when there are no
events.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
|