Getting a live view of environment variables (Gradle and JDK 9)

Martin Buchholz martinrb at
Fri Oct 13 18:21:06 UTC 2017

Actual mutability of the Unix process environment is something we have to
give up when moving to multi-threaded processes.  The only time you get to
change the environment is when running single-threaded, typically around
fork/exec.  Learn to live with it.

The Java System.getenv() is initialized from the Unix environment and is
also immutable.  One could imagine making that mutable in the style of
ConcurrentHashMap and having subprocesses inherit it, but it would open up
a divergence between Java and native.  It's easier for an environment like
gradle to do the same sort of thing, but then there's the same problem -
all the users would need to use exclusively gradle APIs to access the
environment and spawn subprocesses, else the mismatch will cause trouble.

More information about the core-libs-dev mailing list