gpt4 book ai didi

multithreading - Groovy:找不到匹配的构造函数 'subclass'

转载 作者:行者123 更新时间:2023-12-03 13:16:08 26 4
gpt4 key购买 nike

我收到以下错误:

Could not find matching constructor for: org.crawler.CrawlerUtils$fetch(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()
}
}
}

我尝试了这些(丑陋的)方法:
  • 创建一个接口(interface)(使用 ISite 站点而不是 fetch 构造函数中的站点站点)
  • 在 fetch 类
  • 内的每个子类中放置一个构造函数
  • 在每个调用 super()
  • 的子类中放置一个构造函数

    任何的想法?

    最佳答案

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

    static class Fetch implements Runnable

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

    你应该能够做到:
    GParsPool.withPool {
    sites.eachParallel { site -> site.parse() }
    }

    关于multithreading - Groovy:找不到匹配的构造函数 'subclass',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13713502/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com