implementing wait and notify Java alike