Java Wait Timeout While Loop