Groovy:找不到'子类'的匹配构造函数

时间:2012-12-04 22:59:09

标签: multithreading groovy constructor subclass

我收到以下错误:

  

无法找到匹配的构造函数:   org.crawler.CrawlerUtils $撷取(org.series.crawler.site.SubSiteA)。

我正在尝试使用线程。我只使用过一次线程,而我正在努力做到和我在其他项目中做的一样。

我有:

Class CrawlerUtils {
    public static void crawlSites(List<Site> sites) {
        def pool = Executors.newFixedThreadPool(MAX_THREADS)
        def ecs = new ExecutorCompletionService<Void>(pool);
        sites.each { ecs.submit(new fetch(it), Void) }
        sites.each { ecs.take().get() }
        pool.shutdown()
    }

    class fetch implements Runnable {
        Site site
        fetch(Site site) {
            this.site = site
        }
        public void run() {
            site.parse()
        }
    }
}

我尝试了这些(uglies)方法:

  • fetch 构造函数中创建一个接口(使用 ISite站点而不是站点站点
  • fetch
  • 中的每个子类中放置一个构造函数
  • 在每个调用 super()
  • 的子类中放置一个构造函数

有什么想法吗?

1 个答案:

答案 0 :(得分:5)

由于crawlSites是静态的,所以类Fetch(应该有大写字母以遵循任何形式的通用命名方案)也需要是静态的。

static class Fetch implements Runnable

我会使用GPars ...查看this section of the guide

你应该可以这样做:

GParsPool.withPool {
  sites.eachParallel { site -> site.parse() }
}