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) ...

Get Groovy 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.