线程一:
public class MyThread01 extends Thread { @Override public void run() { long start = System.currentTimeMillis(); Integer a =11; for (int i = 0; i < 1000; i++) { a+=i; } long end = System.currentTimeMillis(); System.out.println("线程一耗时:"+(end-start)); } }
线程二:
public class MyThread02 extends Thread { @Override public void run() { long start = System.currentTimeMillis(); String s = ""; for (int i = 0; i < 1000; i++) { s+="黑马程序员"; } long end = System.currentTimeMillis(); System.out.println("线程二耗时:"+(end-start)); } }
线程三:
public class MyThread03 extends Thread { @Override public void run() { long start = System.currentTimeMillis(); String c = ""; for (int i = 0; i < 1000; i++) { c=c+"黑马程序员"+i; } long end = System.currentTimeMillis(); System.out.println("线程三耗时:"+(end-start)); } }
主函数:
public class Test { public static void main(String[] args) { new MyThread01().start(); new MyThread02().start(); new MyThread03().start(); }