Synchronize Java threads using critical section (synchronizes keyword)