是否可以将 i 的值传递给新的线程对象?
当前代码:
int cores = 4;
final int n = 10000;
static double sum = 0.0;
Thread[] threads = new Thread[cores];
for (int i = 0; i < cores; i++)
{
threads[i] = new Thread(new Runnable() {
public void run() {
for (int j = i * (n / cores); j < (i + 1) * N / P; j++) {
double x = (j + 0.5) * step;
sum += 4.0 / (1.0 + x * x);
}
}
});
}
问候