展开全部
那么我们要做的就是把要做的事情开多线程里去62616964757a686964616fe59b9ee7ad9431333365653165处理,可以简单的实现如下package com.wenxy.test.baidu.zhidao.bank;
import java.util.Iterator;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class TestLoop {
public static int i = 0;
void doSomething() {
System.out.println(Thread.currentThread().getName()
+ " is doing。。。 and i = " + i);
i++;
}
public static void main(String[] args) {
final TestLoop testLoop = new TestLoop();
// 创建一个线程池,用10个线程处理
Executor executor = Executors.newFixedThreadPool(10);
for (int i = 0; i
executor.execute(new Runnable() {
@Override
public void run() {
testLoop.doSomething();
}
});
}
}
}