public static void test01() {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
synchronized (lock){
i++;
}
}
long end = System.currentTimeMillis();
System.out.println("test01-耗时:" + (end - start) + "ms. ");
}
// test01-耗时:11ms.
public static void test02() {
long start = System.currentTimeMillis();
synchronized (lock){
for (int i = 0; i < 1000000; i++) {
i++;
}
}
long end = System.currentTimeMillis();
System.out.println("test02-耗时:" + (end - start) + "ms. ");
}
// test02-耗时:2ms.
锁粗化
最新推荐文章于 2024-09-20 22:45:39 发布