Hi,
I have the run method like this:
....
....
public void run()
{
...
while(true)
{
...
//some set of operations
....
Thread.sleep(5*1000*60);
}
In the above code, the sleep operation seems to take a lot of CPU time
though ideally sleep is like a no-op mode, meaning since no operation
is done when a thread sleeps, it should not use any/minimal CPU time.
But it seems to take over 30% of CPU time!
Any ideas on why such a weird thing's happening?
In fact, in one more similar method also, sleep is taking similar CPU
time.
Philipp Leitner - 17 Jul 2006 15:05 GMT
> Hi,
>
[quoted text clipped - 25 lines]
> In fact, in one more similar method also, sleep is taking similar CPU
> time.
Hmmm ... no, on my computer (Mac OS X 10.4, Java 5) I don't have
similar problems:
I wrote something like
public class ThreadTest {
public static void main(String[] args) {
try {
for(;;)
Thread.sleep(5*1000*60);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
to test it, and it does not seem to consume much CPU while sleeping:
902 java 0.0% 0:00.50
/philipp
Raga - 18 Jul 2006 07:10 GMT
Hi Philipp,
I checked the performance statistics when doing a stress test. Maybe,
doing a stress test yields such result??
Regards,
Raga
> > Hi,
> >
[quoted text clipped - 48 lines]
>
> /philipp
pranshu - 17 Jul 2006 17:02 GMT
Hi Raga,
How are you measuring CPU time ?
I guess you are using a profiler.
It is highly likely that your loop is very light - taking 0.01% of
system time - and out of that the sleep method is taking 30%?
essentially being 30% of nothing.
Pranshu
Raga - 18 Jul 2006 07:09 GMT
Yes, I used profiler.
Its not that way. Out of teh total CPU consumption, sleep() in this
method is taking about 30%, which is very high right? This was observed
when a stress test was done. Has it something to do specifically when
stress testing?
Regards,
Raga
> Hi Raga,
> How are you measuring CPU time ?
[quoted text clipped - 5 lines]
>
> Pranshu