Agorreca
Agorreca

Reputation: 686

Groovy: Could not find matching constructor for 'subclass'

I'm getting the following error:

Could not find matching constructor for: org.crawler.CrawlerUtils$fetch(org.series.crawler.site.SubSiteA).

I'm trying to use threads. I used threads only one time, and I'm trying to do the same that I did in the other project.

I have:

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()
        }
    }
}

I tried these (uglies) approaches:

Any idea?

Upvotes: 1

Views: 1648

Answers (1)

tim_yates
tim_yates

Reputation: 171144

As crawlSites is static the class Fetch (should have a capital letter to follow any form of common naming scheme) needs to be static too.

static class Fetch implements Runnable

I'd use GPars though... Looks at this section of the guide

You should be able to do:

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

Upvotes: 5

Related Questions