All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.redismq.samples.rocket.lock.PutMessageSpinLock Maven / Gradle / Ivy

There is a newer version: 0.4.3
Show newest version

package com.redismq.samples.rocket.lock;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Spin lock Implementation to put message, suggest using this with low race conditions
 */
public class PutMessageSpinLock implements  PutMessageLock {
    /**
     *  消息自旋锁
     */
    private final AtomicBoolean putMessageSpinLock = new AtomicBoolean(true);

    @Override
    public void lock() {
        boolean flag;
        do {
            flag = this.putMessageSpinLock.compareAndSet(true, false);
        }
        while (!flag);
    }

    @Override
    public void unlock() {
        this.putMessageSpinLock.compareAndSet(false, true);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy