Use AtomicBoolean in atomic way

In original code it is possible to successfully pass this check with two threads
Merge pull request #26 from vmpn/patch-2

Use AtomicBoolean in atomic way