本文整理匯總了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();
}