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


Java ConcurrentLinkedQueue.remove方法代碼示例

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


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

示例1: main

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
public static void main(String[] args) {
    int i = 0;
    // Without bug fix, OutOfMemoryError was observed at iteration 65120
    int iterations = 10 * 65120;
    try {
        ConcurrentLinkedQueue<Long> queue = new ConcurrentLinkedQueue<>();
        queue.add(0L);
        while (i++ < iterations) {
            queue.add(1L);
            queue.remove(1L);
        }
    } catch (Error t) {
        System.err.printf("failed at iteration %d/%d%n", i, iterations);
        throw t;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:RemoveLeak.java

示例2: testRetainAll

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
/**
 * retainAll(c) retains only those elements of c and reports true if change
 */
public void testRetainAll() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    ConcurrentLinkedQueue p = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.remove();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ConcurrentLinkedQueueTest.java

示例3: put

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
public void put(K key) {
	Iterator<ConcurrentLinkedQueue<K>> it = _buckets.iterator();
	ConcurrentLinkedQueue<K> bucket = it.next();
	bucket.add(key);
	if (isDelete) {
		while (it.hasNext()) {
			bucket = it.next();
			if (contains(key, bucket)) {
				bucket.remove(key);
			}
		}
	}
}
 
開發者ID:langxianwei,項目名稱:iot-plat,代碼行數:14,代碼來源:RotatingList.java

示例4: remove

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
public Object remove(K key) {
	for (ConcurrentLinkedQueue<K> bucket : _buckets) {
		if (contains(key,bucket)) {
			return bucket.remove(key);
		}
	}
	return null;
}
 
開發者ID:langxianwei,項目名稱:iot-plat,代碼行數:9,代碼來源:RotatingList.java

示例5: testEmpty

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
    assertTrue(q.isEmpty());
    q.add(one);
    assertFalse(q.isEmpty());
    q.add(two);
    q.remove();
    q.remove();
    assertTrue(q.isEmpty());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:ConcurrentLinkedQueueTest.java

示例6: testSize

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
/**
 * size changes when elements added and removed
 */
public void testSize() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.size());
        q.remove();
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.size());
        q.add(new Integer(i));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:ConcurrentLinkedQueueTest.java

示例7: testRemove

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

示例8: testRemoveAll

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        ConcurrentLinkedQueue q = populatedQueue(SIZE);
        ConcurrentLinkedQueue p = populatedQueue(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer x = (Integer)(p.remove());
            assertFalse(q.contains(x));
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:ConcurrentLinkedQueueTest.java

示例9: testWeaklyConsistentIteration

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
/**
 * Modifications do not cause iterators to fail
 */
public void testWeaklyConsistentIteration() {
    final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
    q.add(one);
    q.add(two);
    q.add(three);

    for (Iterator it = q.iterator(); it.hasNext();) {
        q.remove();
        it.next();
    }

    assertEquals("queue should be empty again", 0, q.size());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:ConcurrentLinkedQueueTest.java

示例10: addRemove

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
@Test
public void addRemove() {
    ConcurrentLinkedQueue q = new ConcurrentLinkedQueue();
    assertInvariants(q);
    assertNull(item(head(q)));
    assertEquals(nodeCount(q), 1);
    q.add(1);
    assertEquals(nodeCount(q), 2);
    assertInvariants(q);
    q.remove(1);
    assertEquals(nodeCount(q), 1);
    assertInvariants(q);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:WhiteBox.java

示例11: getNeedHeartbeatCons

import java.util.concurrent.ConcurrentLinkedQueue; //導入方法依賴的package包/類
protected LinkedList<RedisBackendConnection> getNeedHeartbeatCons(
		ConcurrentLinkedQueue<RedisBackendConnection> checkLis, long heartbeatTime, long closeTime) {
	
	int maxConsInOneCheck = 10;
	LinkedList<RedisBackendConnection> heartbeatCons = new LinkedList<RedisBackendConnection>();
	
	Iterator<RedisBackendConnection> checkListItor = checkLis.iterator();
	while (checkListItor.hasNext()) {
		RedisBackendConnection con = checkListItor.next();
		if ( con.isClosed() ) {
			checkListItor.remove();
			continue;
		}
		
		// 關閉 閑置過久的 connection
		if (con.getLastTime() < closeTime) {
			if(checkLis.remove(con)) { 
				con.close("heartbeate idle close ");
				continue;
			}
		}
		
		// 提取需要做心跳檢測的 connection
		if (con.getLastTime() < heartbeatTime && heartbeatCons.size() < maxConsInOneCheck) {
			// 如果移除失敗,說明該連接已經被其他線程使用
			if(checkLis.remove(con)) { 
				con.setBorrowed(true);
				heartbeatCons.add(con);
			}
		} 
	}
	
	return heartbeatCons;
}
 
開發者ID:variflight,項目名稱:feeyo-redisproxy,代碼行數:35,代碼來源:AbstractPool.java


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