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


Java ConcurrentLinkedQueue.clear方法代码示例

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


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

示例1: testClear

import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
/**
 * clear removes all elements
 */
public void testClear() {
    ConcurrentLinkedQueue q = populatedQueue(SIZE);
    q.clear();
    assertTrue(q.isEmpty());
    assertEquals(0, q.size());
    q.add(one);
    assertFalse(q.isEmpty());
    q.clear();
    assertTrue(q.isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:ConcurrentLinkedQueueTest.java

示例2: testConnectionsArePooledAsyncCreate

import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testConnectionsArePooledAsyncCreate() throws Exception {
    final MockJMSConnectionFactory mock = new MockJMSConnectionFactory();

    cf = new JmsPoolConnectionFactory();
    cf.setConnectionFactory(mock);
    cf.setMaxConnections(1);

    final ConcurrentLinkedQueue<JmsPoolConnection> connections = new ConcurrentLinkedQueue<JmsPoolConnection>();

    final JmsPoolConnection primary = (JmsPoolConnection) cf.createConnection();
    final ExecutorService executor = Executors.newFixedThreadPool(10);
    final int numConnections = 100;

    for (int i = 0; i < numConnections; ++i) {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    connections.add((JmsPoolConnection) cf.createConnection());
                } catch (JMSException e) {
                }
            }
        });
    }

    assertTrue("All connections should have been created.", Wait.waitFor(new Wait.Condition() {
        @Override
        public boolean isSatisfied() throws Exception {
            return connections.size() == numConnections;
        }
    }, TimeUnit.SECONDS.toMillis(10), TimeUnit.MILLISECONDS.toMillis(50)));

    executor.shutdown();
    assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));

    for (JmsPoolConnection connection : connections) {
        assertSame(primary.getConnection(), connection.getConnection());
    }

    connections.clear();
    cf.stop();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:45,代码来源:JmsPoolConnectionFactoryTest.java

示例3: testConnectionsArePooledAsyncCreate

import java.util.concurrent.ConcurrentLinkedQueue; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testConnectionsArePooledAsyncCreate() throws Exception {

    final ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory(
        "vm://broker1?marshal=false&broker.persistent=false&broker.useJmx=false");
    final JmsPoolConnectionFactory cf = new JmsPoolConnectionFactory();
    cf.setConnectionFactory(amq);
    cf.setMaxConnections(1);

    final ConcurrentLinkedQueue<JmsPoolConnection> connections = new ConcurrentLinkedQueue<JmsPoolConnection>();

    final JmsPoolConnection primary = (JmsPoolConnection) cf.createConnection();
    final ExecutorService executor = Executors.newFixedThreadPool(10);
    final int numConnections = 100;

    for (int i = 0; i < numConnections; ++i) {
        executor.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    connections.add((JmsPoolConnection) cf.createConnection());
                } catch (JMSException e) {
                }
            }
        });
    }

    assertTrue("All connections should have been created.", Wait.waitFor(new Wait.Condition() {
        @Override
        public boolean isSatisfied() throws Exception {
            return connections.size() == numConnections;
        }
    }, TimeUnit.SECONDS.toMillis(10), TimeUnit.MILLISECONDS.toMillis(50)));

    executor.shutdown();
    assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));

    for (JmsPoolConnection connection : connections) {
        assertSame(primary.getConnection(), connection.getConnection());
    }

    connections.clear();
    cf.stop();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:46,代码来源:PooledConnectionFactoryTest.java


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