public boolean isReleasable() { if (thread == null) return true; if (phaser.getPhase() != phase) { thread = null; return true; } if (Thread.interrupted()) wasInterrupted = true; if (wasInterrupted && interruptible) { thread = null; return true; } if (timed) { if (nanos > 0L) { long now = System.nanoTime(); nanos -= now - lastTime; lastTime = now; } if (nanos <= 0L) { thread = null; return true; } } return false; }
/** * Adds the given number of new unarrived parties to this phaser. * If an ongoing invocation of {@link #onAdvance} is in progress, * this method may await its completion before returning. If this * phaser has a parent, and the given number of parties is greater * than zero, and this phaser previously had no registered * parties, this child phaser is also registered with its parent. * If this phaser is terminated, the attempt to register has no * effect, and a negative value is returned. * * @param parties the number of additional parties required to * advance to the next phase * @return the arrival phase number to which this registration * applied. If this value is negative, then this phaser has * terminated, in which case registration has no effect. * @throws IllegalStateException if attempting to register more * than the maximum supported number of parties * @throws IllegalArgumentException if {@code parties < 0} */ public int bulkRegister(int parties) { if (parties < 0) throw new IllegalArgumentException(); if (parties == 0) return getPhase(); return doRegister(parties); }
public boolean isReleasable() { if (thread == null) return true; if (phaser.getPhase() != phase) { thread = null; return true; } if (Thread.interrupted()) wasInterrupted = true; if (wasInterrupted && interruptible) { thread = null; return true; } if (timed) { if (nanos > 0L) { long now = System.nanoTime(); nanos -= now - lastTime; lastTime = now; } if (nanos <= 0L) { thread = null; return true; } } return false; }
public Integer call() throws Exception { return phaser.awaitAdvance(phaser.getPhase() + 1); } });
public Integer call() throws Exception { return phaser.awaitAdvance(phaser.getPhase()); } });
/** * Adds the given number of new unarrived parties to this phaser. * If an ongoing invocation of {@link #onAdvance} is in progress, * this method may await its completion before returning. If this * phaser has a parent, and the given number of parties is greater * than zero, and this phaser previously had no registered * parties, this child phaser is also registered with its parent. * If this phaser is terminated, the attempt to register has no * effect, and a negative value is returned. * * @param parties the number of additional parties required to * advance to the next phase * @return the arrival phase number to which this registration * applied. If this value is negative, then this phaser has * terminated, in which case registration has no effect. * @throws IllegalStateException if attempting to register more * than the maximum supported number of parties * @throws IllegalArgumentException if {@code parties < 0} */ public int bulkRegister(int parties) { if (parties < 0) throw new IllegalArgumentException(); if (parties == 0) return getPhase(); return doRegister(parties); }
private void displayPhaseMessage() { int phase = phaser.getPhase(); if (lastMessageIndex != phase) { lastMessageIndex = phase; message1("Phase:" + phase, ConcurrentExampleConstants.MESSAGE_COLOR); if (phase < 0) { message2(" (Negative value == Phaser terminated)", ConcurrentExampleConstants.MESSAGE_COLOR); } } }
public void run() { message1(String.format("Phase: %d \tRegistered:%d \tArrived:%d \tUnarrived:%d", phaser.getPhase(), phaser.getRegisteredParties(), phaser.getArrivedParties(), phaser.getUnarrivedParties()), ConcurrentExampleConstants.MESSAGE_COLOR); } }, 500, TimeUnit.MILLISECONDS);
@Override protected boolean onAdvance(int phase, int registeredParties) { message1(String.format("Phase: %d \tRegistered:%d \tArrived:%d \tUnarrived:%d", phaser.getPhase(), phaser.getRegisteredParties(), phaser.getArrivedParties(), phaser.getUnarrivedParties()), ConcurrentExampleConstants.WARNING_MESSAGE_COLOR); setState(7); return false; } };