本文整理汇总了Java中java.util.concurrent.ConcurrentLinkedDeque类的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentLinkedDeque类的具体用法?Java ConcurrentLinkedDeque怎么用?Java ConcurrentLinkedDeque使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConcurrentLinkedDeque类属于java.util.concurrent包,在下文中一共展示了ConcurrentLinkedDeque类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: concurrentQueues
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
Collection<Queue<Boolean>> concurrentQueues() {
List<Queue<Boolean>> queues = new ArrayList<Queue<Boolean>>();
queues.add(new ConcurrentLinkedDeque<Boolean>());
queues.add(new ConcurrentLinkedQueue<Boolean>());
queues.add(new ArrayBlockingQueue<Boolean>(count, false));
queues.add(new ArrayBlockingQueue<Boolean>(count, true));
queues.add(new LinkedBlockingQueue<Boolean>());
queues.add(new LinkedBlockingDeque<Boolean>());
queues.add(new LinkedTransferQueue<Boolean>());
// Following additional implementations are available from:
// http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
// queues.add(new SynchronizedLinkedListQueue<Boolean>());
// Avoid "first fast, second slow" benchmark effect.
Collections.shuffle(queues);
return queues;
}
示例2: concurrentQueues
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
Collection<Queue<Integer>> concurrentQueues() {
List<Queue<Integer>> queues = new ArrayList<>();
queues.add(new ConcurrentLinkedDeque<Integer>());
queues.add(new ConcurrentLinkedQueue<Integer>());
queues.add(new ArrayBlockingQueue<Integer>(items, false));
//queues.add(new ArrayBlockingQueue<Integer>(count, true));
queues.add(new LinkedBlockingQueue<Integer>());
queues.add(new LinkedBlockingDeque<Integer>());
queues.add(new LinkedTransferQueue<Integer>());
// Following additional implementations are available from:
// http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
// queues.add(new SynchronizedLinkedListQueue<Integer>());
// Avoid "first fast, second slow" benchmark effect.
Collections.shuffle(queues);
return queues;
}
示例3: concurrentQueues
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
Collection<Queue<Boolean>> concurrentQueues() {
List<Queue<Boolean>> queues = new ArrayList<>();
queues.add(new ConcurrentLinkedDeque<Boolean>());
queues.add(new ConcurrentLinkedQueue<Boolean>());
queues.add(new ArrayBlockingQueue<Boolean>(count, false));
queues.add(new ArrayBlockingQueue<Boolean>(count, true));
queues.add(new LinkedBlockingQueue<Boolean>());
queues.add(new LinkedBlockingDeque<Boolean>());
queues.add(new LinkedTransferQueue<Boolean>());
// Following additional implementations are available from:
// http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
// queues.add(new SynchronizedLinkedListQueue<Boolean>());
// Avoid "first fast, second slow" benchmark effect.
Collections.shuffle(queues);
return queues;
}
示例4: main
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
/**
* Main method of the example. Creates three WriterTasks and a CleanerTask
*
* @param args
*/
public static void main(String[] args) {
// Creates the Event data structure
Deque<Event> deque = new ConcurrentLinkedDeque<>();
// Creates the three WriterTask and starts them
WriterTask writer = new WriterTask(deque);
for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) {
Thread thread = new Thread(writer);
thread.start();
}
// Creates a cleaner task and starts them
CleanerTask cleaner = new CleanerTask(deque);
cleaner.start();
}
开发者ID:PacktPublishing,项目名称:Java-SE-9-Road-to-Concurrent-and-High-Performance-Programming,代码行数:23,代码来源:Main.java
示例5: testRemoveElement
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
/**
* remove(x) removes x and returns true if present
*/
public void testRemoveElement() {
ConcurrentLinkedDeque q = populatedDeque(SIZE);
for (int i = 1; i < SIZE; i += 2) {
assertTrue(q.contains(i));
assertTrue(q.remove(i));
assertFalse(q.contains(i));
assertTrue(q.contains(i - 1));
}
for (int i = 0; i < SIZE; i += 2) {
assertTrue(q.contains(i));
assertTrue(q.remove(i));
assertFalse(q.contains(i));
assertFalse(q.remove(i + 1));
assertFalse(q.contains(i + 1));
}
assertTrue(q.isEmpty());
}
示例6: testRetainAll
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
/**
* retainAll(c) retains only those elements of c and reports true if change
*/
public void testRetainAll() {
ConcurrentLinkedDeque q = populatedDeque(SIZE);
ConcurrentLinkedDeque p = populatedDeque(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();
}
}
示例7: testIteratorRemove
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
/**
* iterator.remove() removes current element
*/
public void testIteratorRemove() {
final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
final Random rng = new Random();
for (int iters = 0; iters < 100; ++iters) {
int max = rng.nextInt(5) + 2;
int split = rng.nextInt(max - 1) + 1;
for (int j = 1; j <= max; ++j)
q.add(new Integer(j));
Iterator it = q.iterator();
for (int j = 1; j <= split; ++j)
assertEquals(it.next(), new Integer(j));
it.remove();
assertEquals(it.next(), new Integer(split + 1));
for (int j = 1; j <= split; ++j)
q.remove(new Integer(j));
it = q.iterator();
for (int j = split + 1; j <= max; ++j) {
assertEquals(it.next(), new Integer(j));
it.remove();
}
assertFalse(it.hasNext());
assertTrue(q.isEmpty());
}
}
示例8: testDescendingIterator
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
/**
* Descending iterator iterates through all elements
*/
public void testDescendingIterator() {
ConcurrentLinkedDeque q = populatedDeque(SIZE);
int i = 0;
Iterator it = q.descendingIterator();
while (it.hasNext()) {
assertTrue(q.contains(it.next()));
++i;
}
assertEquals(i, SIZE);
assertFalse(it.hasNext());
try {
it.next();
shouldThrow();
} catch (NoSuchElementException success) {}
}
示例9: testDescendingIteratorOrdering
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
/**
* Descending iterator ordering is reverse FIFO
*/
public void testDescendingIteratorOrdering() {
final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
for (int iters = 0; iters < 100; ++iters) {
q.add(new Integer(3));
q.add(new Integer(2));
q.add(new Integer(1));
int k = 0;
for (Iterator it = q.descendingIterator(); it.hasNext();) {
assertEquals(++k, it.next());
}
assertEquals(3, k);
q.remove();
q.remove();
q.remove();
}
}
示例10: testDescendingIteratorRemove
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
/**
* descendingIterator.remove() removes current element
*/
public void testDescendingIteratorRemove() {
final ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
final Random rng = new Random();
for (int iters = 0; iters < 100; ++iters) {
int max = rng.nextInt(5) + 2;
int split = rng.nextInt(max - 1) + 1;
for (int j = max; j >= 1; --j)
q.add(new Integer(j));
Iterator it = q.descendingIterator();
for (int j = 1; j <= split; ++j)
assertEquals(it.next(), new Integer(j));
it.remove();
assertEquals(it.next(), new Integer(split + 1));
for (int j = 1; j <= split; ++j)
q.remove(new Integer(j));
it = q.descendingIterator();
for (int j = split + 1; j <= max; ++j) {
assertEquals(it.next(), new Integer(j));
it.remove();
}
assertFalse(it.hasNext());
assertTrue(q.isEmpty());
}
}
示例11: initialize
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
public boolean initialize(Class<?> cls, ConcurrentLinkedDeque<String> alerts) {
mThreat_alerts = alerts;
if (cls == ConnectorMThreatModuleRest.class) {
module = new ConnectorMThreatModuleRest();
for (int i = 0; i < THREADS_NUMBER; i++) {
executor.execute(this);
}
isRunning = true;
return true;
}
return false;
}
示例12: Metrics
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
/**
* Instantiates a new Metrics.
*
* @param period the period
* @param maxSegmentNumber the max segment number
*/
public Metrics(Long period, Integer maxSegmentNumber) {
this.period = period;
this.maxSegmentNumber = maxSegmentNumber;
this.metricsDeque = new ConcurrentLinkedDeque<>();
SegmentMetrics newMetrics = new SegmentMetrics();
this.metricsDeque.addFirst(newMetrics);
}
示例13: init
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public synchronized void init() {
// Byte: [-128, 127]
final int length = 256;
this.guiElements = new ConcurrentLinkedDeque<>();
this.gameElements = (Queue<GameElement>[]) new Queue<?>[length];
for (int i = 0; i < this.gameElements.length; i++) {
this.gameElements[i] = new ArrayDeque<>();
}
this.gameElementAddQueue = new ArrayDeque<>();
this.gameElementRemoveQueue = new ArrayDeque<>();
// never start the game in paused state
this.setPause(false);
}
示例14: testsForConcurrentLinkedDeque
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
public Test testsForConcurrentLinkedDeque() {
return QueueTestSuiteBuilder.using(
new TestStringQueueGenerator() {
@Override
public Queue<String> create(String[] elements) {
return new ConcurrentLinkedDeque<String>(MinimalCollection.of(elements));
}
})
.named("ConcurrentLinkedDeque")
.withFeatures(
CollectionFeature.GENERAL_PURPOSE, CollectionFeature.KNOWN_ORDER, CollectionSize.ANY)
.suppressing(suppressForConcurrentLinkedDeque())
.createTestSuite();
}
示例15: DefaultAccessLogReceiver
import java.util.concurrent.ConcurrentLinkedDeque; //导入依赖的package包/类
public DefaultAccessLogReceiver(final Executor logWriteExecutor, final File outputDirectory, final String logBaseName, final String logNameSuffix) {
this.logWriteExecutor = logWriteExecutor;
this.outputDirectory = outputDirectory;
this.logBaseName = logBaseName;
this.logNameSuffix = (logNameSuffix != null) ? logNameSuffix : DEFAULT_LOG_SUFFIX;
this.pendingMessages = new ConcurrentLinkedDeque<>();
this.defaultLogFile = new File(outputDirectory, logBaseName + this.logNameSuffix);
calculateChangeOverPoint();
}