Forgot to sleep in a non-blocking thread, causing CPU issues.
Also, only flush if you actually have something to flush (not sure if that makes any difference).

Fixes #73.
Make gradlew executable.