本文整理汇总了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());
}
示例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();
}
示例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();
}