我是编程和Java的初学者,这是我的第一个多核程序.问题是我的程序从不使用超过13%的CPU.我不知道我是否以正确的方式做到了.
如何更快地计算并使用更多CPU资源?
我的课程包括三个课程:
"使用多个线程实例化Work对象的主类
一个"T1"类,它扩展了Thread并包含要执行的工作
一个"工作"类,用于启动所需的线程编号并显示所有线程执行工作所花费的时间
这是我Main班级的代码:
public static void main(String[] args) {
System.out.println("Number of CPUs available = " + Runtime.getRuntime().availableProcessors()); //Display the number of CPUs available
int iteration = 100000000; // Define a number of itterations to do by all threads
/*
Instantiates each work with a different number of threads (1, 4, 8, 12, and 24)
*/
Work t1 = new Work(1);
Work t4 = new Work(4);
Work t8 = new Work(8);
Work t12 = new …Run Code Online (Sandbox Code Playgroud)