#stream

Getting a usable, non-localhost IP address for a JVM

I recently had a task where I needed to inform a docker image of the host OS’ IP address. (The docker image needed to make an HTTP call to the host machine, for testing purposes.) However, it’s not trivial to find code to actually get a host machine’s IP address. Here’s some code in Kotlin (and in Java) to accomplish the task; I can’t say it’s perfect (and won’t...

2 minute(s) read

Interesting Links – 24 Oct 2016

The Way of the Lambda – Elegant and Efficient discusses using Java 8’s removeIf to remove elements from collections, as opposed to removing them via an iterator, and shows graphs to show the improvement. One claim (via Reddit) was that it was O(1) but here the claim is a little more reasonable. Another thing from the post was that the author says that he’s “recently … spent a few years away from Java development...

2 minute(s) read

How to execute a group of tasks

Someone on the channel today asked about how to run a series of tasks, with a terminal condition of sorts. Basically, they wanted to run a number of tasks, and know when they were done. The question was originally built around having a List of results (List<integer>, maybe?), counting the number of results until the number of results matched the number of tasks. The channel suggested using an ExecutorService, particularly the shutdown...

3 minute(s) read