Re: Thread.sleep takes lot of CPU time!
- From: "Philipp Leitner" <philipp.leitner@xxxxxx>
- Date: 17 Jul 2006 07:05:19 -0700
Raga wrote:
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.
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
.
- References:
- Thread.sleep takes lot of CPU time!
- From: Raga
- Thread.sleep takes lot of CPU time!
- Prev by Date: Re: Simple question: bounded generics
- Next by Date: what's better way to store a million keys in mem?
- Previous by thread: Thread.sleep takes lot of CPU time!
- Next by thread: Re: Thread.sleep takes lot of CPU time!
- Index(es):
Relevant Pages
|