org.jctools.queues.MpmcArrayQueue Java Examples
The following examples show how to use
org.jctools.queues.MpmcArrayQueue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MpmcPollTest.java From akarnokd-misc with Apache License 2.0 | 6 votes |
@Test public void unsafe() { for (int i = 0; i < 100000; i++) { MpmcArrayQueue<Integer> q = new MpmcArrayQueue<>(128); q.offer(1); Integer[] result = new Integer[] { 2, 2 }; race(() -> { result[0] = q.poll(); }, () -> { result[1] = q.poll(); }, exec); assertTrue(Arrays.toString(result), (result[0] == null && result[1] == 1) || (result[0] == 1 && result[1] == null)); } }
Example #2
Source File: MpmcBenchmark.java From tutorials with MIT License | 6 votes |
@Setup(Level.Trial) public void setUp() { switch (implementation) { case PARAM_UNSAFE: queue = new MpmcArrayQueue<>(CAPACITY); break; case PARAM_AFU: queue = new MpmcAtomicArrayQueue<>(CAPACITY); break; case PARAM_JDK: queue = new ArrayBlockingQueue<>(CAPACITY); break; default: throw new UnsupportedOperationException("Unsupported implementation " + implementation); } }
Example #3
Source File: ObjectPoolBenchmark.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Setup public void setUp() { tracer = new ElasticApmTracerBuilder().buildAndStart(); blockingQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new ArrayBlockingQueue<>(256), true, () -> new Transaction(tracer)); jctoolsQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new MpmcArrayQueue<>(256), true, () -> new Transaction(tracer)); jctoolsAtomicQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue<>(256), true, () -> new Transaction(tracer)); agronaQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new ManyToManyConcurrentArrayQueue<>(256), true, () -> new Transaction(tracer)); threadLocalObjectPool = new ThreadLocalObjectPool<>(64, true, () -> new Transaction(tracer)); }
Example #4
Source File: MpmcArrayBuffer.java From caffeine with Apache License 2.0 | 4 votes |
MpmcArrayBuffer() { queue = new MpmcArrayQueue<>(BUFFER_SIZE); }
Example #5
Source File: ThreadLocalVsPoolBenchmark.java From logging-log4j2 with Apache License 2.0 | 4 votes |
private JcPool(final int capacity) { this.stringBuilders = new MpmcArrayQueue<>(capacity); }
Example #6
Source File: RecyclerFactories.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public static RecyclerFactory ofSpec(final String recyclerFactorySpec) { // Determine the default capacity. int defaultCapacity = Math.max( 2 * Runtime.getRuntime().availableProcessors() + 1, 8); // TLA-, MPMC-, or ABQ-based queueing factory -- if nothing is specified. if (recyclerFactorySpec == null) { if (Constants.ENABLE_THREADLOCALS) { return ThreadLocalRecyclerFactory.getInstance(); } else { final Supplier<Queue<Object>> queueSupplier = JCTOOLS_QUEUE_CLASS_AVAILABLE ? () -> new MpmcArrayQueue<>(defaultCapacity) : () -> new ArrayBlockingQueue<>(defaultCapacity); return new QueueingRecyclerFactory(queueSupplier); } } // Is a dummy factory requested? else if (recyclerFactorySpec.equals("dummy")) { return DummyRecyclerFactory.getInstance(); } // Is a TLA factory requested? else if (recyclerFactorySpec.equals("threadLocal")) { return ThreadLocalRecyclerFactory.getInstance(); } // Is a queueing factory requested? else if (recyclerFactorySpec.startsWith("queue")) { return readQueueingRecyclerFactory(recyclerFactorySpec, defaultCapacity); } // Bogus input, bail out. else { throw new IllegalArgumentException( "invalid recycler factory: " + recyclerFactorySpec); } }