FYI: You can get notified of the reaching a memory threshold after garbage collection using ManagementFactory.getMemoryMXBean()
The downside of using runtime.freeMemory is that it will only decrease once a GC has gone through. So it will underestimate the actual free memory, possibly flushing more often that you want (which is probably fine).
https://techblug.wordpress.com/2011/07/21/detecting-low-memory-in-java-part-2/
However, the notification is asynchronous.