how to find cpu is idle or not???

M

master007

hi...

how to find cpu is idle or not using java programming...
bye..
frnds...
waiting for ur reply..
 
E

Eric Sosman

master007 wrote On 02/16/06 12:38,:
hi...

how to find cpu is idle or not using java programming...
bye..
frnds...
waiting for ur reply..

static boolean CPUIsIdle() {
return false;
}

.... because the CPU cannot be idle if it's executing
the method.

What's your *real* question?
 
B

Bent C Dalager

static boolean CPUIsIdle() {

I would recommend "isCpuIdle()" in stead :)
return false;
}

... because the CPU cannot be idle if it's executing
the method.

There could presumably be a callback the CPU could invoke when it
knows that it otherwise would have been idle though.

Cheers
Bent D
 
O

Oliver Wong

Eric Sosman said:
master007 wrote On 02/16/06 12:38,:

static boolean CPUIsIdle() {
return false;
}

... because the CPU cannot be idle if it's executing
the method.

What's your *real* question?

What if the user has a multi-cpu machine, and the Java code is running
on one CPU, but querying a different CPU? ;)

- Oliver
 
E

Eric Sosman

Oliver Wong wrote On 02/16/06 13:53,:
What if the user has a multi-cpu machine, and the Java code is running
on one CPU, but querying a different CPU? ;)

That's the sort of clarification I hope he'll offer,
along with what he means by "CPU" and by "idle." I also
admit to some puzzlement about why he thinks an answer
would be useful ...
 
M

master007

Sir...
iam doing file searcher in hard disk.
i have to scan the hard disk...
if i scan the comp when it is loaded...system performance will be
degraded..
so i want to know wheather cpu is idle or not..?
if it is idle..i can use that time ...with causing inconvience to
user...

I think u Got my Point Sir...

ThankU Sir...
 
R

Roedy Green

so i want to know wheather cpu is idle or not..?

you could detect that by creating a very low priority thread that did
something inane like compute pi. You check in on it after a second
to see how much it has accomplished. If a lot, then the machine is
idle.
 
A

Alun Harford

master007 said:
Sir...
iam doing file searcher in hard disk.
i have to scan the hard disk...
if i scan the comp when it is loaded...system performance will be
degraded..
so i want to know wheather cpu is idle or not..?

No you don't - you just want to schedule the thread with minimum priority.
If the JVM is any good, Java threads are mapped to OS threads, and it'll get
run with minimum priority by the OS.

Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

Alun Harford
 
D

Dimitri Maziuk

master007 sez:
Sir...
iam doing file searcher in hard disk.
i have to scan the hard disk...
if i scan the comp when it is loaded...system performance will be
degraded..
so i want to know wheather cpu is idle or not..?

You can't: it's like opening the box except the cat is dead
100% of the time.

The code for checking must be executed by the cpu, so when
the check runs cpu will always be busy -- running the check.

HTH,HAND
Dima
 
O

Oliver Wong

master007 said:
Sir...
iam doing file searcher in hard disk.
i have to scan the hard disk...
if i scan the comp when it is loaded...system performance will be
degraded..
so i want to know wheather cpu is idle or not..?
if it is idle..i can use that time ...with causing inconvience to
user...

I think u Got my Point Sir...

ThankU Sir...

I made a post about this earlier. See

http://tinyurl.com/jvvad

(original URL is:

http://groups.google.ca/group/comp....1e4ce9a2ece/ceaa37335d33440e#ceaa37335d33440e

)

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top