State variable should be volatile
Got rid of warning message for unused System.in.read()
Synchronization related improvements and extracted handler in preparation for #2