Code example for AtomicLong

Methods: compareAndSet, get

0
     * unset. 
     * 
     * @param timestamp A timestamp corresponding to the time of the notification 
     */ 
    public void requestCheckout(long timestamp) {
        long lastTimestamp = lastNotificationTime.get();
        if (checkoutRequested.get() || timestamp <= lastTimestamp) {
            // If a checkout is already requested or the current timestamp is older than a 
            // previously encountered timestamp we will ignore this request 
            return; 
        } 
 
        // Check whether another thread has beaten the current thread to it. 
        // If the lastNotificationTime has changed since the last check, then some other thread 
        // has already set the checkoutRequested flag 
        if (lastNotificationTime.compareAndSet(lastTimestamp, timestamp)) {
            if (log.isDebugEnabled()) {
                log.debug("Checkout operation requested");
            } 
            checkoutRequested.compareAndSet(false, true);
        }