List of usage examples for java.util.concurrent.atomic AtomicReferenceFieldUpdater set
public abstract void set(T obj, V newValue);
From source file:org.apache.distributedlog.BKLogSegmentWriter.java
void scheduleFlushWithDelayIfNeeded(final Callable<?> callable, final AtomicReferenceFieldUpdater<BKLogSegmentWriter, ScheduledFuture> scheduledFutureRefUpdater) { final long delayMs = Math.max(0, minDelayBetweenImmediateFlushMs - lastTransmit.elapsed(TimeUnit.MILLISECONDS)); final ScheduledFuture scheduledFuture = scheduledFutureRefUpdater.get(this); if ((null == scheduledFuture) || scheduledFuture.isDone()) { scheduledFutureRefUpdater.set(this, scheduler.schedule(new Runnable() { @Override//from w ww . j av a 2s .com public void run() { synchronized (this) { scheduledFutureRefUpdater.set(BKLogSegmentWriter.this, null); try { callable.call(); // Flush was successful or wasn't needed, the exception should be unset. scheduledFlushExceptionUpdater.set(BKLogSegmentWriter.this, null); } catch (Exception exc) { scheduledFlushExceptionUpdater.set(BKLogSegmentWriter.this, exc); LOG.error("Delayed flush failed", exc); } } } }, delayMs, TimeUnit.MILLISECONDS)); } }