Using OptimizeIT (a superb product, too bad it costs at least $300), I finally found out why IndexClient is eating CPU cycles.
 
It's the Ticker class. A Ticker is created with a tickerTime of 0 ms - thus the ticker never sleeps and constantly polls its event queue.
 
The Ticker is created by Core() that passes the value of the static variable Core.tickerTime to the Ticker constructor - and Core.tickerTime is 0.
 
What happens is this:
 
-in the beginning, Core.tickerTime is 0 (VM default value)
-IndexClient(Params, Logger) creates a SimplifiedClient
--SimplifiedClient(Params, Logger) (indirectly) calls CLI(Params, Logger, boolean)
---CLI(Params, Logger, boolean) calls ClientUtil.getServiceCore(int)
----ClientUtil.getServiceCore(int) creates a ClientCore
-----ClientCore(ListeningAddress, Presentation) calls the Core constructor
------Core(ListeningAddress, Presentation, HandshakeHandler) creates a Timer with a tickerTime value of 0 => BANG!
--now SimplifiedClient(Params, Logger) calls Core.init(Params) which sets Core.tickerTime to a reasonable value -- but it's already TOO LATE!
 
A workaround is to call Core.init(someParams) before creating the first IndexClient. I leave devising a real bug fix to Brandon... ;-)
 
Also, I have no idea why this doesn't happen on non-Windows platforms. Maybe a sleep(0) does sleep for a few ms on Unix...?
 
BTW: I leeched Freenet from CVS 4 weeks ago or so - I hope this trackdown isn't obsolete by now...
 
-Stefan
 

Reply via email to