java 1.6 exposes the system load average

See the javadoc.

Example usage:


public class LoadAverage {
    public static void main(String[] args) {
        final OperatingSystemMXBean osStats =
        final double loadAverage = osStats.getSystemLoadAverage();
        System.out.println(String.format("load average: %f", loadAverage));

This is a rather useful feature if you are writing software that should do less when the overall system load is high.

For example, if you’re me, you might be working on a java daemon that is instructing some CouchDB instances on the same box to do database compactions and/or replications, and you could use this to tune down the concurrency or the frequency if the load average is above a threshold.

%d bloggers like this: