package com.puple.atto.datastructure; public class ThreadTest extends Thread{ @Override public void run() { long beginTime=System.currentTimeMillis(); System.out.println("线程开始执行时间:"+beginTime); int count=0; for (int i=0;i<50000000;i++) { Thread.yield(); //调用yield()方法,暂时不用 count=count+(i+1); } long endTime=System.currentTimeMillis(); System.out.println("线程结束执行时间:"+endTime); System.out.println("本次执行用时:"+(endTime-beginTime)+"毫秒!"); } public static void main(String[] args) { ThreadTest thread=new ThreadTest(); //创建MyThread12线程实例 thread.start(); //启动线程 } }
yield注释与否运行时间相差巨大
原文地址:https://www.cnblogs.com/linwenbin/p/11801618.html
时间: 2024-10-09 02:12:13