for循环是我们编程中经常用到的,但是如果每一次循环中耗时较久,那么整个程序就会很慢,甚至超时,下面我就来改进一下这种情况。
public class TestSynchronizedFor {
private static final int num = 10;
public static void main(String args[]) throws InterruptedException {
TestSynchronizedFor testSynchronizedFor = new TestSynchronizedFor();
long at = System.currentTimeMillis();
testSynchronizedFor.start();
long et3 = System.currentTimeMillis();
System.out.println("总耗时:"+(et3 - at)+ "ms");
}
public static void start() {
for (int index = 0; index < num; index++) {
try {
new Thread().sleep<