added synchronized block around Thread.sleep