Simple thread synchronisation in Java