Race condition avoided using synchronized method.