如何将参数传递给 a Thread
?
该语句log( "before process , counter = " + i);
导致错误:
不能在不同方法中定义的内部类中引用非最终变量 i
请帮忙
for (int i = 0; i < 20; i++) {
Thread thread = ThreadManager.createThreadForCurrentRequest(new Runnable() {
public void run() {
try {
log("before process , counter = " + i);
Thread.sleep(1000);
log("after process , " + "counter = " + i);
} catch (InterruptedException ex) {
throw new RuntimeException("Interrupted in loop:", ex);
}
}
});
thread.start();
}