當前位置: 首頁>>代碼示例>>Java>>正文


Java DelayQueue.poll方法代碼示例

本文整理匯總了Java中java.util.concurrent.DelayQueue.poll方法的典型用法代碼示例。如果您正苦於以下問題:Java DelayQueue.poll方法的具體用法?Java DelayQueue.poll怎麽用?Java DelayQueue.poll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.DelayQueue的用法示例。


在下文中一共展示了DelayQueue.poll方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testElement

import java.util.concurrent.DelayQueue; //導入方法依賴的package包/類
/**
 * element returns next element, or throws NSEE if empty
 */
public void testElement() {
    DelayQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(new PDelay(i), q.element());
        q.poll();
    }
    try {
        q.element();
        shouldThrow();
    } catch (NoSuchElementException success) {}
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:DelayQueueTest.java

示例2: testContains

import java.util.concurrent.DelayQueue; //導入方法依賴的package包/類
/**
 * contains(x) reports true when elements added but not yet removed
 */
public void testContains() {
    DelayQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.contains(new PDelay(i)));
        q.poll();
        assertFalse(q.contains(new PDelay(i)));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:DelayQueueTest.java

示例3: main

import java.util.concurrent.DelayQueue; //導入方法依賴的package包/類
/**
 * @param args
 */
public static void main(String[] args) throws Exception {

	/*
	 * Delayed queue to store the events
	 */
	DelayQueue<Event> queue = new DelayQueue<>();

	/*
	 * An array to store the Thread objects that execute the tasks
	 */
	Thread threads[] = new Thread[5];

	/*
	 * Create the five tasks
	 */
	for (int i = 0; i < threads.length; i++) {
		Task task = new Task(i + 1, queue);
		threads[i] = new Thread(task);
	}

	/*
	 * Execute the five tasks
	 */
	for (int i = 0; i < threads.length; i++) {
		threads[i].start();
	}

	/*
	 * Wait for the finalization of the five tasks
	 */
	for (int i = 0; i < threads.length; i++) {
		threads[i].join();
	}

	/*
	 * Write the results to the console
	 */
	do {
		int counter = 0;
		Event event;
		do {
			event = queue.poll();
			if (event != null)
				counter++;
		} while (event != null);
		System.out.printf("At %s you have read %d events\n", new Date(), counter);
		TimeUnit.MILLISECONDS.sleep(500);
	} while (queue.size() > 0);
}
 
開發者ID:PacktPublishing,項目名稱:Java-9-Concurrency-Cookbook-Second-Edition,代碼行數:53,代碼來源:Main.java


注:本文中的java.util.concurrent.DelayQueue.poll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。