ArthurDn ArthurDn - 1 year ago 65
Java Question

What is the safest way to check AtomicBoolean and perform something?

Are any ways to make this operations like one operatinon (kind of custom atomic)?

if (!isShutdownStarted.get()
&& !QUEUE.contains(request.getUserEmail())) {
try {

Code in other thread

public void contextDestroyed(ServletContextEvent servletContextEvent) {
while (!PaymentClient.QUEUE.isEmpty());

Answer Source

You cannot use an AtomicBoolean to make another operation or sequence of operations atomic.

If you need to make an intrinsically non-atomic operation or sequence atomic, you need to use locking; e.g. a primitive mutex, a Lock or something equivalent.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download