Use AtomicBoolean instead of synchronize the whole method