How to Push Java Performance to Its Limit
Hi there,
I use java version 1.4.2.09 in HP-UX with 8 CPUs and 4GB Memories.
I add -Xmx3072m & -Xms3072m parameters in a startup of certain java application.
the java and the application run well. But, it use only 120%CPU. It means that it only use 2 CPUs.
The question is: How can I make the java application run using all available resources (8 CPUs)?
I have tuned the memory to reach almost 4GB (3072M), now all its left is how to maximize CPU usage to almost 800% (all CPUs are used).
is there any clue for this?
thanks
# 1
You may not have written your application in a way that it can use all 8 cpu's concurrently.
Run the code below. It should use all 8 of your CPU's.
public class Spin implements Runnable {
public static void main(String[] args) {
int threads = Runtime.getRuntime().availableProcessors();
if (args.length > 0) {
threads = Integer.parseInt(args[0]);
}
for (int i=0; i<threads; i++) {
new Thread(new Spin(),"Spin " + i).start();
}
}
public void run() {
for(long i=0; i><10000000000; i++) {
if (i % 10000000 == 0) {
System.out.println("Thread \"" + Thread.currentThread().getName() + "\" is on iteration " + i);
}
}
}
}