produce cpu usage

How do i write a java code which can produce cpu usage 30-70% // how ?cpu usage 70-90% // how ?cpu usage 100% // this can be done with a while loop .
[184 byte] By [navigatora] at [2007-10-1 23:22:15]
# 1
I don't think you can.
mlka at 2007-7-15 14:07:17 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

you could do a while loop for 100% usage, but have it periodically sleep to reduce the overall usage. Remember that usage is a relative term, for single processor system, all processes are 100% cpu usage (while they're using the cpu) and that the values reported by the OS (20%, 40% whatever) are averages over some time interval.

Brenta at 2007-7-15 14:07:17 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
you're going to have to monitor the CPU state over time and increase/decrease the load on the CPU as you go until you get it locked at whatever % you want, but it won't be gauranteed since other processes will be running
SoulTech2012a at 2007-7-15 14:07:17 > top of Java-index,Other Topics,Patterns & OO Design...
# 4
> monitor the CPU stateHow?
mlka at 2007-7-15 14:07:18 > top of Java-index,Other Topics,Patterns & OO Design...
# 5
JNI.
pm_kirkhama at 2007-7-15 14:07:18 > top of Java-index,Other Topics,Patterns & OO Design...
# 6
> JNI.sure, you can do all this in native.you can't in "pure" java.
mlka at 2007-7-15 14:07:18 > top of Java-index,Other Topics,Patterns & OO Design...
# 7

> you can't in "pure" java.

Well you have windows, linux, solaris, mac, etc., and they all do things a bit differently. Java is platform independent and runs on all of these platforms, so any time Java implements something platform specific in the VM, they have to do it several times. Thus, you get limited support for such features, not to mention Java is a high level language with high level API's. What you're asking for is a very low level operation. So JNI is sometimes the only solution.

SoulTech2012a at 2007-7-15 14:07:18 > top of Java-index,Other Topics,Patterns & OO Design...