當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。