Concurrency

Reusing threads and objects via ThreadLocal

Threads in Java are expensive – they require allocation of large blocks of memory, are tracked via descriptors which have to be created and maintained by the JVM, and require numerous system calls to register the thread with the underlying operating system. Thread pool executors help solve this problem by enabling developers to create and maintain thread pools which re-use threads as the executor responds to queued work. This thread re-use enables quicker turn around on submitted jobs to the executor without resource overuse by the system.
Read more

A concurrent, Groovy thread ripper

This was a fun bit; using Apache Tika to detect MIME types of files on your machine with little code and effort. The script takes a location, the root location from which to recurse, and generates a set of absolute paths to scrutinize. It then establishes a latch equal to the size of the set to block reporting until the analysis is complete. The script then iterates through the absolute paths, submitting jobs to the executor for processing, which each hold a reference to a thread safe map and counter object use for tallying.
Read more