当前位置: 首页>>代码示例>>Java>>正文


Java ScheduledThreadPoolExecutor.getQueue方法代码示例

本文整理汇总了Java中java.util.concurrent.ScheduledThreadPoolExecutor.getQueue方法的典型用法代码示例。如果您正苦于以下问题:Java ScheduledThreadPoolExecutor.getQueue方法的具体用法?Java ScheduledThreadPoolExecutor.getQueue怎么用?Java ScheduledThreadPoolExecutor.getQueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ScheduledThreadPoolExecutor的用法示例。


在下文中一共展示了ScheduledThreadPoolExecutor.getQueue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGetQueue

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * getQueue returns the work queue, which contains queued tasks
 */
public void testGetQueue() throws InterruptedException {
    final CountDownLatch done = new CountDownLatch(1);
    final ScheduledThreadPoolExecutor p = new CustomExecutor(1);
    try (PoolCleaner cleaner = cleaner(p, done)) {
        final CountDownLatch threadStarted = new CountDownLatch(1);
        ScheduledFuture[] tasks = new ScheduledFuture[5];
        for (int i = 0; i < tasks.length; i++) {
            Runnable r = new CheckedRunnable() {
                public void realRun() throws InterruptedException {
                    threadStarted.countDown();
                    await(done);
                }};
            tasks[i] = p.schedule(r, 1, MILLISECONDS);
        }
        await(threadStarted);
        BlockingQueue<Runnable> q = p.getQueue();
        assertTrue(q.contains(tasks[tasks.length - 1]));
        assertFalse(q.contains(tasks[0]));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ScheduledExecutorSubclassTest.java

示例2: test

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
void test(ScheduledThreadPoolExecutor p) throws Throwable {
    Runnable dummy = new Runnable() { public void run() {
        throw new AssertionError("shouldn't get here"); }};
    BlockingQueue q = p.getQueue();
    ReentrantLock lock = getField(q, "lock");
    Condition available = getField(q, "available");

    equal(0, p.getPoolSize());
    equal(0, p.getLargestPoolSize());
    equal(0L, p.getTaskCount());
    equal(0L, p.getCompletedTaskCount());
    p.schedule(dummy, 1L, HOURS);
    // Ensure one pool thread actually waits in timed queue poll
    awaitHasWaiters(lock, available, LONG_DELAY_MS);
    equal(1, p.getPoolSize());
    equal(1, p.getLargestPoolSize());
    equal(1L, p.getTaskCount());
    equal(0L, p.getCompletedTaskCount());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ZeroCoreThreads.java

示例3: testListeningDecorator_cancelled

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
public void testListeningDecorator_cancelled() throws Exception {
  ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(1);
  BlockingQueue<?> delegateQueue = delegate.getQueue();
  ListeningScheduledExecutorService service = listeningDecorator(delegate);
  ListenableFuture<?> future;
  ScheduledFuture<?> delegateFuture;

  Runnable runnable = new Runnable() {
    @Override public void run() {}
  };

  future = service.schedule(runnable, 5, TimeUnit.MINUTES);
  future.cancel(true);
  assertTrue(future.isCancelled());
  delegateFuture = (ScheduledFuture<?>) delegateQueue.element();
  assertTrue(delegateFuture.isCancelled());

  delegateQueue.clear();

  future = service.scheduleAtFixedRate(runnable, 5, 5, TimeUnit.MINUTES);
  future.cancel(true);
  assertTrue(future.isCancelled());
  delegateFuture = (ScheduledFuture<?>) delegateQueue.element();
  assertTrue(delegateFuture.isCancelled());

  delegateQueue.clear();

  future = service.scheduleWithFixedDelay(runnable, 5, 5, TimeUnit.MINUTES);
  future.cancel(true);
  assertTrue(future.isCancelled());
  delegateFuture = (ScheduledFuture<?>) delegateQueue.element();
  assertTrue(delegateFuture.isCancelled());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:34,代码来源:MoreExecutorsTest.java

示例4: testRemove

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * remove(task) removes queued task, and fails to remove active task
 */
public void testRemove() throws InterruptedException {
    final CountDownLatch done = new CountDownLatch(1);
    final ScheduledThreadPoolExecutor p = new CustomExecutor(1);
    try (PoolCleaner cleaner = cleaner(p, done)) {
        ScheduledFuture[] tasks = new ScheduledFuture[5];
        final CountDownLatch threadStarted = new CountDownLatch(1);
        for (int i = 0; i < tasks.length; i++) {
            Runnable r = new CheckedRunnable() {
                public void realRun() throws InterruptedException {
                    threadStarted.countDown();
                    await(done);
                }};
            tasks[i] = p.schedule(r, 1, MILLISECONDS);
        }
        await(threadStarted);
        BlockingQueue<Runnable> q = p.getQueue();
        assertFalse(p.remove((Runnable)tasks[0]));
        assertTrue(q.contains((Runnable)tasks[4]));
        assertTrue(q.contains((Runnable)tasks[3]));
        assertTrue(p.remove((Runnable)tasks[4]));
        assertFalse(p.remove((Runnable)tasks[4]));
        assertFalse(q.contains((Runnable)tasks[4]));
        assertTrue(q.contains((Runnable)tasks[3]));
        assertTrue(p.remove((Runnable)tasks[3]));
        assertFalse(q.contains((Runnable)tasks[3]));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:ScheduledExecutorSubclassTest.java

示例5: testGetQueue

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * getQueue returns the work queue, which contains queued tasks
 */
public void testGetQueue() throws InterruptedException {
    final CountDownLatch done = new CountDownLatch(1);
    final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
    try (PoolCleaner cleaner = cleaner(p, done)) {
        final CountDownLatch threadStarted = new CountDownLatch(1);
        ScheduledFuture[] tasks = new ScheduledFuture[5];
        for (int i = 0; i < tasks.length; i++) {
            Runnable r = new CheckedRunnable() {
                public void realRun() throws InterruptedException {
                    threadStarted.countDown();
                    await(done);
                }};
            tasks[i] = p.schedule(r, 1, MILLISECONDS);
        }
        await(threadStarted);
        BlockingQueue<Runnable> q = p.getQueue();
        assertTrue(q.contains(tasks[tasks.length - 1]));
        assertFalse(q.contains(tasks[0]));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ScheduledExecutorTest.java

示例6: testRemove

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * remove(task) removes queued task, and fails to remove active task
 */
public void testRemove() throws InterruptedException {
    final CountDownLatch done = new CountDownLatch(1);
    final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
    try (PoolCleaner cleaner = cleaner(p, done)) {
        ScheduledFuture[] tasks = new ScheduledFuture[5];
        final CountDownLatch threadStarted = new CountDownLatch(1);
        for (int i = 0; i < tasks.length; i++) {
            Runnable r = new CheckedRunnable() {
                public void realRun() throws InterruptedException {
                    threadStarted.countDown();
                    await(done);
                }};
            tasks[i] = p.schedule(r, 1, MILLISECONDS);
        }
        await(threadStarted);
        BlockingQueue<Runnable> q = p.getQueue();
        assertFalse(p.remove((Runnable)tasks[0]));
        assertTrue(q.contains((Runnable)tasks[4]));
        assertTrue(q.contains((Runnable)tasks[3]));
        assertTrue(p.remove((Runnable)tasks[4]));
        assertFalse(p.remove((Runnable)tasks[4]));
        assertFalse(q.contains((Runnable)tasks[4]));
        assertTrue(q.contains((Runnable)tasks[3]));
        assertTrue(p.remove((Runnable)tasks[3]));
        assertFalse(q.contains((Runnable)tasks[3]));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:ScheduledExecutorTest.java


注:本文中的java.util.concurrent.ScheduledThreadPoolExecutor.getQueue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。