Recently the subject came up on the LRUG mailing list of the easiest way to download multiple images quickly. The conversation started with Typheous and ended with shelling out to the command line with wget and parallel… All good and solid solutions.
However there’s one solution I’d like to go into that involves thread pools. If you’re lucky enough to not be constrained by dogma and are able to use JRuby, then you’ll have access to the lovely java.util.concurrent library.
Wait, did I just use the word Java? It’s OK, don’t panic. We’re not going to write any Java per se, but we are going to use a battle hardened library that has such niceties as thread safe data structures and high level concurrency semantics such as thread pools.
Threaded code can be hard to write/debug and the guys in JVM land realised this a very long time ago. Rather than just bitching and waiting for Scala to be the new standard, they instead developed j.v.c to ease the life of developers everywhere.
In order to demonstrate how easy it is to get some concurrency utilising thread pools, I wrote an extremely simple/naïve script for concurrent file downloading.
This is literally just scratching the surface of j.u.c. More JRuby/concurrency related subjects to follow in the coming weeks.