欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java用CPU使用率画正弦曲线,java正弦,纯属娱乐,关闭其他消耗C

来源: javaer 分享于  点击 8460 次 点评:270

java用CPU使用率画正弦曲线,java正弦,纯属娱乐,关闭其他消耗C


纯属娱乐,关闭其他消耗CPU的进程,打开windows任务管理器的性能选项卡就可以看到效果^_^

[Java]代码

package nonproject.test;/** * * @author Wang7x */public class Main {    public static final double TIME = 1000;    /**     * @param args the command line arguments     */    public static void main(String[] args) throws InterruptedException {        double x = 0;        double y = 0;        while (true) {            y = (Math.sin(x) + 1) * TIME / 2;            doSomeSimpleWork(y);            x += 0.1;            Thread.sleep((long) (TIME - y));        }    }    private static void doSomeSimpleWork(double y) {        long startTime = System.currentTimeMillis();        while ((System.currentTimeMillis() - startTime) < y) {        }    }}
相关栏目:

用户点评