this synchronized can be avoided using an AtomicBoolean