我遇到了这个错误:
没有外围类GeoLocation的实例可访问。 必须使用GeoLocation类型的外围实例来限定分配(例如,x.new A()其中x是GeoLocation的实例)。 这个错误发生在new 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);
}
}
}