当前位置: 首页>>代码示例>>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;未经允许,请勿转载。