CPU.java package fun; import java.util.*; public class CPU{ /** * Valiables * */ private double GHz=1.83; private static final double MARKGHZ=1.83; private double rate=1; /** * Methods * */ /** * CPU(double GHz) * */ CPU(double GHz) { this.GHz=GHz; rate=this.GHz/MARKGHZ; } CPU(){} /** * 计时器 * runForSeconds(double seconds) * */ public void runForSeconds(double seconds){ double now=new Date().getTime(); double end=new Date().getTime(); while((end-now)<seconds*1000){ run(); end=new Date().getTime(); } } /** * 让CPU使用率提高50% * */ public void run(){ } /** * 50 * */ public static void fifty(){ int len=1000;//与该值无关 int[] a=new int[len]; for(int i=0;i<len;i++){ a[i]=new Random().nextInt(len);//此处无效 } } /** * 80 * */ public static void eighty(){ System.out.println(new Date()); } } rock it package fun; import java.io.*; public class CpuHack { /** * Valiables * */ /** * Methods * */ /** * main */ public static void main(String[] args) { //CPU cpu=new CPU(1.86); //cpu.runForSeconds(0); Fifty f=new Fifty(); Eighty e=new Eighty(); f.runForSeconds(7); e.runForSeconds(6); f.runForSeconds(9); } } class Fifty extends CPU{ public void run() { CPU.fifty(); } } class Eighty extends CPU{ public void run() { CPU.eighty(); } }