Java: What is the different between AtomicBoolean and a static boolean variable when locking a thread?

Viewed 4214

I write a thread class called T.

My purpose is to make sure only one thread object running at a time.

So when the thread object is called, it would check a boolean flag called BUSY.

My question is what is the different between

private static AtomicBoolean BUSY = new AtomicBoolean(false);

and

private static boolean BUSY = false;

I thought if using the 'static', all object would only check one BUSY boolean variable so that would make sure only one thread object is running.

4 Answers
Related