r****m 发帖数: 70 | 1 package test;
public class MapTest implements Runnable{
int[] a;
int index = 0;
MapTest(int[] a) {
this.a = a;
}
int fun(int i) {
return i+1;
}
@Override
public void run() {
int i;
while((i = getIndex()) < a.length) {
System.out.println(Thread.currentThread().getName() + " " + i);
a[i] = fun(a[i]);
}
}
synchronized int getIndex() {
return (index++);
}
static... 阅读全帖 |
|