I am sure your solution will work, But I want to mention that using synchronized block is deprecated and has no more use. For additional information, read java.util.concurrency package in JDK Javadocs.