Are any ways to make this operations like one operatinon (kind of custom atomic)?
if (!isShutdownStarted.get()
&& !QUEUE.contains(request.getUserEmail())) {
try {
QUEUE.add(request.getUserEmail());
}
//...
}
Code in other thread
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
PaymentClient.isShutdownStarted.set(true);
while (!PaymentClient.QUEUE.isEmpty());
}
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; eg a primitive mutex, a Lock
or something equivalent.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.