O'Reilly logo

Groovy 2 Cookbook by Luciano Fiandesio, Andrey Adamovich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Downloading files concurrently

This recipe is about downloading files concurrently from the network. As for most recipes in this chapter, we will use the GPars framework to leverage the concurrent features required by the parallel downloading.

Getting ready

This recipe reuses the same build infrastructure created in the Processing collections concurrently recipe.

How to do it...

The download logic is completely encapsulated in a Groovy class.

  1. Add a new FileDownloader class to the src/main/groovy/org/groovy/cookbook folder:
    package org.groovy.cookbook import static groovyx.gpars.GParsPool.* import static com.google.common.collect.Lists.* class FileDownloader { static final int POOL_SIZE = 25 static pool FileDownloader() { pool = createPool(POOL_SIZE) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required