我收到此错误为-
无法访问类型为GeoLocation的封闭实例。必须用一个封闭的GeoLocation类型的实例(例如xxA(),其中x是GeoLocation的实例)来限定分配。新的ThreadTask(i)上将出现此错误。我不知道为什么会这样。任何建议将不胜感激。
public class GeoLocation {
public static void main(String[] args) throws InterruptedException {
int size = 10;
// create thread pool with given size
ExecutorService service = Executors.newFixedThreadPool(size);
// queue some tasks
for(int i = 0; i < 3 * size; i++) {
service.submit(new ThreadTask(i));
}
// wait for termination
service.shutdown();
service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
}
class ThreadTask implements Runnable {
private int id;
public ThreadTask(int id) {
this.id = id;
}
public void run() {
System.out.println("I am task " + id);
}
}
}
2
看到这个答案:stackoverflow.com/questions/633585/...
—
hmjd