日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

分布与并行计算—用任务管理器画CPU正弦曲线(Java)

發布時間:2023/11/29 java 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 分布与并行计算—用任务管理器画CPU正弦曲线(Java) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

class drawSin implements Runnable{@Overridepublic void run() {final double SPLIT = 0.01;// 角度的分割final int COUNT = (int) (2 / SPLIT);// 2PI分割的次數,也就是2/0.01個,正好是一周final double PI = Math.PI;final int interval = 100;// 時間間隔long[] busy = new long[COUNT];//線程運行時間long[] idle= new long[COUNT];//線程休眠時間int half = interval / 2;double x = 0.0;for (int i = 0; i < COUNT; i++) {busy[i] = (long) (half + (Math.sin(PI * x) * half))/2;idle[i] = interval - busy[i];x += SPLIT;}long start = 0;int j = 0;while (true){j = j % COUNT;start = System.currentTimeMillis();while (System.currentTimeMillis() - start < busy[j]) ;try {Thread.sleep(idle[j]);} catch (InterruptedException e) {e.printStackTrace();}j++;}} } public class cpuSin {public static void main(String[] args) throws Exception {Runtime runtime = Runtime.getRuntime();//獲得當前系統的CPU數量,根據這個數值創建對應數量的線程ExecutorService executorService = Executors.newFixedThreadPool(runtime.availableProcessors());for (int i = 0;i < runtime.availableProcessors();i++){//每個核心都上一個線程executorService.execute(new drawSin());}executorService.shutdown();} }

總結

以上是生活随笔為你收集整理的分布与并行计算—用任务管理器画CPU正弦曲线(Java)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。