org.jctools.queues.MpscLinkedQueue Java Examples

The following examples show how to use org.jctools.queues.MpscLinkedQueue. 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: TestQueues2.java    From util4j with Apache License 2.0 6 votes vote down vote up
protected static QueueGroupExecutor buildStageByMpMc(int min,int max,int maxPendingTask)
{
	int maxQueueCount=maxPendingTask;
	//多生产多消费者队列(线程竞争队列)
	Queue<Runnable> bossQueue=new MpmcAtomicArrayQueue<>(maxQueueCount);
	QueueFactory qf=new QueueFactory() {
		@Override
		public RunnableQueue buildQueue() {
			//多生产单消费者队列(PS:bossQueue决定了一个队列只能同时被一个线程处理)
			Queue<Runnable> queue=MpscLinkedQueue.newMpscLinkedQueue();
			return new RunnableQueueWrapper(queue);
		}
	};
	QueueGroupManager kqm=new DefaultQueueManager(qf);
	DefaultQueueGroupExecutor.Builder b=new DefaultQueueGroupExecutor.Builder();
	b.setAssistExecutor(Executors.newSingleThreadExecutor());
	return b.setMaxPoolSize(max).setCorePoolSize(min).setBossQueue(bossQueue).setQueueGroupManagerr(kqm).build();
}
 
Example #2
Source File: TestDefaultQueues.java    From util4j with Apache License 2.0 6 votes vote down vote up
protected static QueueGroupExecutor buildStageByMpMc(int min,int max,int maxQueue,int maxQueuePendingTask)
{
	//多生产多消费者队列(线程竞争队列)
	Queue<Runnable> bossQueue=new ConcurrentLinkedQueue<>();
	QueueFactory qf=new QueueFactory() {
		@Override
		public RunnableQueue buildQueue() {
			//多生产单消费者队列(PS:bossQueue决定了一个队列只能同时被一个线程处理)
			Queue<Runnable> queue=MpscLinkedQueue.newMpscLinkedQueue();
			return new RunnableQueueWrapper(queue);
		}
	};
	QueueGroupManager kqm=new DefaultQueueManager(qf,0);
	DefaultQueueGroupExecutor.Builder b=new DefaultQueueGroupExecutor.Builder();
	b.setAssistExecutor(Executors.newSingleThreadExecutor());
	return b.setMaxPoolSize(max).setCorePoolSize(min).setKeepAliveTime(3, TimeUnit.SECONDS).setBossQueue(bossQueue).setQueueGroupManagerr(kqm).setWaitConditionStrategy(new SleepingWaitConditionStrategy()).build();
}
 
Example #3
Source File: TestQueueGroup2.java    From util4j with Apache License 2.0 6 votes vote down vote up
protected QueueGroupExecutor buildByMpMc(int minThread,int maxThread,int maxQueue,int maxPendingTask)
{
	//多生产多消费者队列(线程竞争队列)
	Queue<Runnable> bossQueue=new MpscArrayQueue<>(maxQueue);
	QueueFactory qf=new QueueFactory() {
		@Override
		public RunnableQueue buildQueue() {
			//多生产单消费者队列(PS:bossQueue决定了一个队列只能同时被一个线程处理)
			Queue<Runnable> queue=MpscLinkedQueue.newMpscLinkedQueue();
			return new RunnableQueueWrapper(queue);
		}
	};
	QueueGroupManager kqm=new DefaultQueueManager(qf);
	NioQueueGroupExecutor.Builder b=new NioQueueGroupExecutor.Builder();
	b.setAssistExecutor(Executors.newSingleThreadExecutor());
	return b.setMaxPoolSize(minThread).setCorePoolSize(maxThread).setBossQueue(bossQueue).setQueueGroupManagerr(kqm).build();
}
 
Example #4
Source File: TestQueueGroup3.java    From util4j with Apache License 2.0 6 votes vote down vote up
protected static QueueGroupExecutor buildByMpMc(int min,int max,int maxPendingTask)
{
	int maxQueueCount=maxPendingTask;
	//多生产多消费者队列(线程竞争队列)
	Queue<Runnable> bossQueue=new MpmcAtomicArrayQueue<>(maxQueueCount);
	QueueFactory qf=new QueueFactory() {
		@Override
		public RunnableQueue buildQueue() {
			//多生产单消费者队列(PS:bossQueue决定了一个队列只能同时被一个线程处理)
			Queue<Runnable> queue=MpscLinkedQueue.newMpscLinkedQueue();
			return new RunnableQueueWrapper(queue);
		}
	};
	QueueGroupManager kqm=new DefaultQueueManager(qf);
	NioQueueGroupExecutor.Builder b=new NioQueueGroupExecutor.Builder();
	b.setAssistExecutor(Executors.newSingleThreadExecutor());
	NioQueueGroupExecutor e= b.setMaxPoolSize(max).setCorePoolSize(min).setBossQueue(bossQueue).setQueueGroupManagerr(kqm)
			.build();
	for(int i=0;i<max;i++)
	{
		e.addWorkerIfNecessary();
	}
	return e;
}
 
Example #5
Source File: MpscBenchmark.java    From java-Kcp with Apache License 2.0 5 votes vote down vote up
@Setup(Level.Trial)
public void setUp() {
    switch (implementation) {
        case PARAM_UNSAFE:
            queue = new MpscArrayQueue<>(CAPACITY);
            break;
        case PARAM_AFU:
            queue = new MpscAtomicArrayQueue<>(CAPACITY);
            break;
        case PARAM_JDK:
            queue = new ArrayBlockingQueue<>(CAPACITY);
            break;
        case PARAM_LINKED:
            queue = new MpscChunkedArrayQueue<>(CAPACITY);
            break;
        case PARAM_JDK_LINK:
            queue = new LinkedBlockingQueue<>(CAPACITY);
            break;
        case PARAM_LINKED_GROUP:
            queue = new MpscGrowableAtomicArrayQueue<>(CAPACITY);
            break;
        case PARAM_MPSC_LINKED:
            queue = new MpscLinkedQueue<>();
            break;
        case PARAM_MPMC_LINKED_ATOMICQUEUE:
            queue = new MpscLinkedAtomicQueue<>();
            break;
        default:
            throw new UnsupportedOperationException("Unsupported implementation " + implementation);
    }
}
 
Example #6
Source File: MpscaBenchmark.java    From java-Kcp with Apache License 2.0 5 votes vote down vote up
@Setup(Level.Trial)
public void setUp() {
    switch (implementation) {
        case PARAM_Linked:
            queue = new MpscLinkedQueue<>();
            break;
        case PARAM_LINKED_ATOMICQUEUE:
            queue = new MpscLinkedAtomicQueue<>();
            break;
        default:
            throw new UnsupportedOperationException("Unsupported implementation " + implementation);
    }
}
 
Example #7
Source File: TestJctools.java    From util4j with Apache License 2.0 5 votes vote down vote up
/**
 * 链表队列
 */
public void teste5()
{
	MpscLinkedQueue[] qs=new MpscLinkedQueue[65535];
	for(int i=0;i<qs.length;i++)
	{
		qs[i]=MpscLinkedQueue.newMpscLinkedQueue();
	}
}
 
Example #8
Source File: PlatformDependent.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
static <T> Queue<T> newUnboundedLinkedMpscQueue() {
    return USE_UNSAFE_QUEUES ? new MpscLinkedQueue<>()
                             : new MpscLinkedAtomicQueue<>();
}
 
Example #9
Source File: OrderedThreadSession.java    From java-Kcp with Apache License 2.0 4 votes vote down vote up
public OrderedThreadSession() {
    this(new MpscLinkedQueue<>());
}