java.util.concurrent.DelayQueue#put ( )源码实例Demo

下面列出了java.util.concurrent.DelayQueue#put ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: spectator   文件: Scheduler.java
/**
 * Execute the task and if reschedule another execution.
 *
 * @param queue
 *     Queue for the pool. This task will be added to the queue to schedule
 *     future executions.
 * @param stats
 *     Handle to stats that should be updated based on the execution of the
 *     task.
 */
@SuppressWarnings("PMD.AvoidCatchingThrowable")
void runAndReschedule(DelayQueue<DelayedTask> queue, Stats stats) {
  thread = Thread.currentThread();
  boolean scheduleAgain = options.schedulingPolicy != Policy.RUN_ONCE;
  try {
    if (!isDone()) {
      task.run();
    }
  } catch (Throwable t) {
    // This catches Throwable because we cannot control the task and thus cannot
    // ensure it is well behaved with respect to exceptions.
    LOGGER.warn("task execution failed", t);
    stats.incrementUncaught(t);
    scheduleAgain = !options.stopOnFailure;
  } finally {
    thread = null;
    if (scheduleAgain && !isDone()) {
      updateNextExecutionTime(stats.skipped());
      queue.put(this);
    } else {
      cancelled = true;
    }
  }
}
 
源代码2 项目: openjdk-jdk9   文件: DelayQueueTest.java
/**
 * all elements successfully put are contained
 */
public void testPut() {
    DelayQueue q = new DelayQueue();
    for (int i = 0; i < SIZE; ++i) {
        PDelay x = new PDelay(i);
        q.put(x);
        assertTrue(q.contains(x));
    }
    assertEquals(SIZE, q.size());
}
 
源代码3 项目: openjdk-jdk9   文件: DelayQueueTest.java
/**
 * drainTo empties queue
 */
public void testDrainToWithActivePut() throws InterruptedException {
    final DelayQueue q = populatedQueue(SIZE);
    Thread t = new Thread(new CheckedRunnable() {
        public void realRun() {
            q.put(new PDelay(SIZE + 1));
        }});

    t.start();
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertTrue(l.size() >= SIZE);
    t.join();
    assertTrue(q.size() + l.size() >= SIZE);
}
 
源代码4 项目: j2objc   文件: DelayQueueTest.java
/**
 * all elements successfully put are contained
 */
public void testPut() {
    DelayQueue q = new DelayQueue();
    for (int i = 0; i < SIZE; ++i) {
        PDelay x = new PDelay(i);
        q.put(x);
        assertTrue(q.contains(x));
    }
    assertEquals(SIZE, q.size());
}
 
源代码5 项目: j2objc   文件: DelayQueueTest.java
/**
 * drainTo empties queue
 */
public void testDrainToWithActivePut() throws InterruptedException {
    final DelayQueue q = populatedQueue(SIZE);
    Thread t = new Thread(new CheckedRunnable() {
        public void realRun() {
            q.put(new PDelay(SIZE + 1));
        }});

    t.start();
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertTrue(l.size() >= SIZE);
    t.join();
    assertTrue(q.size() + l.size() >= SIZE);
}