Use a synchronized block

http://ideone.com/I9t8rl