小编E.B*_*onn的帖子

Java多线程程序没有使用大量的CPU

我是编程和Java的初学者,这是我的第一个多核程序.问题是我的程序从不使用超过13%的CPU.我不知道我是否以正确的方式做到了.

如何更快地计算并使用更多CPU资源?

我的课程包括三个课程:

  1. "使用多个线程实例化Work对象的主类

  2. 一个"T1"类,它扩展了Thread并包含要执行的工作

  3. 一个"工作"类,用于启动所需的线程编号并显示所有线程执行工作所花费的时间

这是我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)

java performance multithreading cpu-usage

2
推荐指数
1
解决办法
112
查看次数

标签 统计

cpu-usage ×1

java ×1

multithreading ×1

performance ×1