When do I need to use AtomicBoolean in Java?

前端 未结 5 1775
情话喂你
情话喂你 2020-12-02 03:55

How I can use AtomicBoolean and what is that class for?

5条回答
  •  忘掉有多难
    2020-12-02 04:49

    The AtomicBoolean class gives you a boolean value that you can update atomically. Use it when you have multiple threads accessing a boolean variable.

    The java.util.concurrent.atomic package overview gives you a good high-level description of what the classes in this package do and when to use them. I'd also recommend the book Java Concurrency in Practice by Brian Goetz.

提交回复
热议问题