标签:ring port out main pac str class 测试 lis
package cn.com.one;
import java.util.ArrayList;
public class ttt {
public static void main(String [] args) {
new Thread(()->{
Thread.currentThread().setName("t2");
int k =0;
String test2 = "";
long startTime2 = System.currentTimeMillis();
ArrayList<Object> arrayList2= new ArrayList<>(10);
while(true){
k += 1;
test2 = "我是第"+k+"个";
arrayList2.add(test2);
if(k > 10000000) break;
}
long overTime2 = System.currentTimeMillis();
System.out.println(Thread.currentThread().getName()+(overTime2 - startTime2) / 1000+"s");
}).start();
//----------------------------------------------------------------------------------------------------
Runnable runnable = ()->{
Thread.currentThread().setName("t1");
int j =0;
String test1 = "";
long startTime1 = System.currentTimeMillis();
ArrayList<Object> arrayList1 = new ArrayList<>(100);
while (true) {
j += 1;
test1 = "我是第" + j + "个";
arrayList1.add(test1);
if (j > 10000000) break;
}
long overTime1 = System.currentTimeMillis();
System.out.println(Thread.currentThread().getName()+(overTime1 - startTime1) / 1000 + "s");
};
//----------------------------------------------------------------------------------------------------
Thread.currentThread().setName("tmain");
int i =0;
String test0 = "";
long startTime0 = System.currentTimeMillis();
ArrayList<Object> arrayList0= new ArrayList<>(1);
while(true){
i += 1;
test0 = "我是第"+i+"个";
arrayList0.add(test0);
if(i > 10000000) break;
}
long overTime0 = System.currentTimeMillis();
System.out.println(Thread.currentThread().getName()+(overTime0 - startTime0) / 1000+"s");
//----------------------------------------------------------------------------------------------------
}
}
标签:ring port out main pac str class 测试 lis
原文地址:https://www.cnblogs.com/mrerror/p/10066907.html