ComputeThread computeThread =newComputeThread();long startTime =System.currentTimeMillis();
computeThread.start();
computeThread.join();long endTime =System.currentTimeMillis();System.out.println("线程执行100亿次循环耗时 -> "+(endTime - startTime));classComputeThreadextendsThread{@Overridepublicvoidrun(){long num=0;//100亿次for循环for(long i =0; i <10000000000L; i++){
num++;}}}
线程停顿的两种方式
List item
classWuJiangextendsThread{@Overridepublicvoidrun(){for(int i =0; i <10;){System.out.println(getName()+"正在战场上厮杀 -> "+(i +1));//线程停顿3stry{Thread.sleep(3000);}catch(InterruptedException e){thrownewRuntimeException(e);}}}}