通知下一个weight任务可以被执行

@throws InterruptedException
322489
public synchronized void single(long weight) throws InterruptedException {
        this.weights.remove(weight);
        // 触发下一个可运行的weight
        Long nextWeight = this.weights.peek();
        if (nextWeight != null) {
            barrier.single(nextWeight);
        }
    }
151745
public void onFailure() throws InterruptedException {
        int val = currentFailureCount.incrementAndGet();
        if (val > 50) {
            currentFailureCount.compareAndSet(val, MAX_FAILURE_COUNT);
            val = MAX_FAILURE_COUNT;
        }

        int delay = MIN_DELAY + ((MAX_DELAY - MIN_DELAY) / MAX_FAILURE_COUNT) * val;

        synchronized (this) {
            Logger.d(TAG, "onFailure: wait " + delay + " ms");
            wait(delay);
        }
    }
305313
public void run() {
        logger.trace("BlockingConsumer " + this + " starting data processing");

        int length;
        char cs[] = new char[256];
        Reader reader = pair.getReader();

        while (!stopRequested && !foundEOF) {
            try {
                logger.trace("BlockingConsumer " + this + " reading from reader");
                length = reader.read(cs); // blocking
            } catch (IOException ioe) {
                // The reader most likely closed on us.
                logger.warn("Caught an exception while reading: " + ioe);
                logger.debug("Assuming EOF");
                foundEOF = true;
                break;
            }

            if (length == -1) { //EOF
                logger.debug("BlockingConsumer " + this + " detected EOF");
                logger.trace("Remaining buffer: " + buffer.toString());
                foundEOF = true;
                break;
            }

            // don't modify the buffer while processing is happening
            // written as while loop to prevent spurious interrupts
            logger.trace("BlockingConsumer " + this + " waiting for synchronized access before appending");
            synchronized(this) { // this could be just before notify, I think
                if (logger.isDebugEnabled()) {
                    logger.debug("BlockingConsumer " + this + " appending " + length + " characters to the buffer");

                    // TODO: this replace operation is done a few places, perhaps utility class?
                    String print = new String(cs, 0, length);
                    print = print.replaceAll("\n", "\\\\n");
                    print = print.replaceAll("\r", "\\\\r");
                    logger.debug("Adding to buffer: " + print);

                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < length; i++)
                        sb.append("," + ((int) cs[i]) );
                    logger.trace("Codes: " + sb.toString());
                }
                buffer.append(cs, 0, length); // thread safe

                /**
                 * TODO Trim down buffer.  This current method won't work if a resume comes in, since it's offset
                 * will be invalid once this delete method runs
                 *
                 * // since we only added one char, we should only have to remove one
                 * if (buffer.length() > BUFFERMAX)
                 *     buffer.delete(0, BUFFERMAX - buffer.length());
                 */

                logger.trace("BlockingConsumer " + this + " notifying listeners of buffer change");
                notify(); // seeing that we read something, wake people up

                // We explicitly call this after appending to the
                // buffer, just in case one of the BufferChangeLoggers
                // accidentally modifies the character buffer.
                notifyBufferChange(cs, length);
            } // end synchronized(this)
        } // end while loop

        logger.trace("BlockingConsumer " + this + " notifying listeners upon ceasing");
        synchronized(this) {
            notify();
        }

        if (stopRequested) {
            logger.debug("BlockingConsumer " + this + " stop requested");
            pair.close();
        }

        if (foundEOF)
            logger.debug("BlockingConsumer " + this + " found EOF to stop while loop");
    }

    /**
     * TODO: what if something came in between when we last checked and
     *       when this method is called
     *
     * @param timeout timeout in milliseconds
     */
    public void waitForBuffer(long timeout) {
        if (foundEOF) {
            logger.trace("BlockingConsumer " + this + " wanted to wait for buffer but found EOF");
            return;
        }

        logger.trace("BlockingConsumer " + this + " ynching on this to wait");
        logger.trace("BlockingConsumer " + this + " waiting for synchronized access before waiting");
        synchronized(this) {
            try {
                if (timeout > 0) {
                    logger.trace("BlockingConsumer " + this + " waiting for " + timeout + " msec for some additional event");
                    wait(timeout);
                } else {
                    logger.trace("BlockingConsumer " + this + " waiting forever for some additional event");
                    wait();
                }
            } catch (InterruptedException ie) {
                logger.trace("BlockingConsumer " + this + " woken up while waiting for buffer");
            }
        }
    }

    /**
     * TODO
     *
     * @return TODO
     */
    public String pause() {
        // TODO mark offset, so that it can be trimmed by resume coming in later
        String currentBuffer;
        currentBuffer = buffer.toString();
        return currentBuffer;
    }

    /**
     * Resume processing from the specified offset.
     *
     * @param offset the offset into the buffer (1-indexed) from which
     *               to start
     */
    public void resume(int offset) {
        if (offset < 0)
            return;

        synchronized(this) {
            logger.trace("BlockingConsumer " + this + " moving buffer up by " + offset);
            StringBuffer smaller = buffer.delete(0, offset); // + 1
        }
    }

    /**
     * A method to test the <code>BlockingConsumer</code> class independently.
     *
     * @param args command line arguments (none used)
     */
    public static void main(String args[]) throws Exception {
        final StringBuffer buffer = new StringBuffer("The lazy fox");

        Thread t1 = new Thread() {
            public void run() {
                synchronized(buffer) {
                    buffer.delete(0,4);
                    buffer.append(" in the middle");
                    System.err.println("Middle");
                    try {
                        Thread.sleep(4000);
                    } catch (Exception e) {}
                    buffer.append(" of fall");
                    System.err.println("Fall");
                }
            }
        };

        Thread t2 = new Thread() {
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {}
                buffer.append(" jump over the fence");
                System.err.println("Fence");
            }
        };

        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.err.println(buffer);
    }
}
588074
@Override
	public final Void get() throws InterruptedException, ExecutionException {
		block(0);
		if (!isUnblocked()) throw new InterruptedException();
		if (hasError()) throw new ExecutionException(error);
		if (isCancelled()) throw new ExecutionException(cancelled);
		return null;
	}
330543
@Override
	public void put(E e) throws InterruptedException {
		if (sizeLimit > 0){
	        final ReentrantLock lock = this.sizeLimitLock;
	        lock.lockInterruptibly();
	        try {
	            try {
	                while (size() >= sizeLimit)
	                    withinSizeLimit.await();
	            } catch (InterruptedException ie) {
	            	withinSizeLimit.signal(); // propagate to non-interrupted thread
	                throw ie;
	            }
	            queue.put(e);
	        } finally {
	            lock.unlock();
	        }
		}else{
			queue.put(e);
		}
	}
943165
@Override
	public final T get() throws InterruptedException, ExecutionException {
		block(0);
		if (!isUnblocked()) throw new InterruptedException();
		if (hasError()) throw new ExecutionException(error);
		if (isCancelled()) throw new ExecutionException(cancel);
		return result;
	}
324510
@Override
    public Message call() throws InterruptedException {
        AbstractExpectation.LOGGER.info("Thread blocked waiting for message to pass condition {}.",
                this.getBlockingCondition());
        try {
            this.latch.await();
            this.manager.unsetExpectation(this);
            AbstractExpectation.LOGGER.info("Condition passed.");
            if (this.actionFuture != null) {
                this.waitUntilActionComplete();
            }
            AbstractExpectation.LOGGER.info("Expectation processing passed.");
            return this.stash;
        } finally {
            this.manager.unsetExpectation(this); // in case await() throws
            this.actionFuture = null;
            AbstractExpectation.LOGGER.info("Thread unblocked.");
        }
    }
1002430
public void start() throws InterruptedException, ExecutionException {
        Future<?> task = es.submit(handlePartitionChange);
        task.get();
    }
158234
public JobStatus.State reload() throws InterruptedException {
    // [START ]
    while (!JobStatus.State.DONE.equals(job.getStatus().getState())) {
      Thread.sleep(1000L);
      job = job.reload();
    }
    // [END ]
    return job.getStatus().getState();
  }
240793
public static void main(String[] args) throws InterruptedException {

    Microservices gateway =
        Microservices.builder()
            .discovery(ScalecubeServiceDiscovery::new)
            .transport(ServiceTransports::rsocketServiceTransport)
            .startAwait();

    Microservices ms =
        Microservices.builder()
            .discovery(
                serviceEndpoint -> serviceDiscovery(serviceEndpoint, gateway.discovery().address()))
            .transport(ServiceTransports::rsocketServiceTransport)
            .services(new DefaultMarketDataService())
            .startAwait();

    MarketDataService marketService = ms.call().api(MarketDataService.class);

    marketService.orderBook().subscribe(Example1::print);

    Executors.newScheduledThreadPool(1)
        .scheduleAtFixedRate(
            () -> {
              try {

                if (RANDOM.nextInt(2) == 1) {
                  marketService
                      .processOrder(
                          new OrderRequest(
                              new Order(
                                  new PriceLevel(Side.BUY, RANDOM.nextInt(10) + 1), // prices
                                  System.currentTimeMillis(),
                                  Long.valueOf(RANDOM.nextInt(110) + 1 + "")), // units
                              INSTRUMENT))
                      .block();
                } else {
                  marketService
                      .processOrder(
                          new OrderRequest(
                              new Order(
                                  new PriceLevel(Side.SELL, RANDOM.nextInt(10) + 1), // prices
                                  System.currentTimeMillis(),
                                  Long.valueOf(RANDOM.nextInt(70) + 1 + "")), // units
                              INSTRUMENT))
                      .block();
                }
              } catch (Throwable ex) {
                ex.printStackTrace();
              }
            },
            3,
            3,
            TimeUnit.MILLISECONDS);

    Thread.currentThread().join();
  }
1126678
@Override
	public void run() {
		Stopwatch stopwatch = SimonManager.getStopwatch(NAME);
		try (Split ignored = stopwatch.start();) {
			sleep(SLEEP);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		// signal to latch that the thread is finished
		latch.countDown();
	}
1294482
@Override public boolean block() throws InterruptedException {
    while( !isDone() ) {
      try { get(); }
      catch(ExecutionException eex) { // skip the execution part
        Throwable tex = eex.getCause();
        if( tex instanceof                 Error) throw (                Error)tex;
        if( tex instanceof  DistributedException) throw ( DistributedException)tex;
        if( tex instanceof JobCancelledException) throw (JobCancelledException)tex;
        throw new RuntimeException(tex);
      }
      catch(CancellationException cex) { Log.errRTExcept(cex); }
    }
    return true;
  }
1302147
@Override
    public V get() throws InterruptedException, ExecutionException {
        V v = super.get();
        this.mergeWorkerTracyTheadContext();
        return v;
    }
642795
private int getQueueSizeAndRetry(RabbitTemplate template, QueueSizeCallBack queueSizeCallBack)
            throws InterruptedException
    {
        int size = 0;
        try
        {
            size = template.execute(queueSizeCallBack);
        }
        catch (AmqpException ex)
        {
            // 接続断のタイミングにより、例外が出力される場合があるため、間隔をあけてリトライする。
            // 再度発生した例外は呼び出し元に返す。
            Thread.sleep(getRetryInterval());
            size = template.execute(queueSizeCallBack);
        }
        return size;
    }
971345
@Override
    public T take(final WaitStrategy.Takeable<T> t) throws InterruptedException {
        T result;

        while ((result = t.take()) == null) {
            Thread.yield();
        }

        return result;
    }
795890
public Long peek() throws InterruptedException {
        lock.lockInterruptibly();
        try {
            while (queue.size() == 0) {
                notEmpty.await();
            }

            return queue.peek();
        } finally {
            lock.unlock();
        }
    }
579152
@Override
    public final T poll(final long timeout, final TimeUnit unit) throws InterruptedException {
        final long start = getWriteLockWithOptionalWait(timeout, unit);
        if (start == Long.MIN_VALUE) {
            // Min value signals a timeout while waiting
            return null;
        }
        final long maxWait = start >= 0 ? unit.toMillis(timeout) : -1;

        try {
            // Wait for an element to be available to return
            if (!this.waitForAdd(start, maxWait)) {
                return null;
            }

            return this.pollInternal(false);
        } finally {
            this.writeLock.unlock();
        }
    }