Search in sources :

Example 1 with MPSCQueue

use of com.hazelcast.internal.util.concurrent.MPSCQueue in project hazelcast by hazelcast.

the class OperationExecutorImpl method initPartitionThreads.

private PartitionOperationThread[] initPartitionThreads(HazelcastProperties properties, HazelcastThreadGroup threadGroup, NodeExtension nodeExtension) {
    int threadCount = properties.getInteger(PARTITION_OPERATION_THREAD_COUNT);
    if (threadCount <= 0) {
        // default partition operation thread count
        int coreSize = Runtime.getRuntime().availableProcessors();
        threadCount = Math.max(2, coreSize);
    }
    PartitionOperationThread[] threads = new PartitionOperationThread[threadCount];
    for (int threadId = 0; threadId < threads.length; threadId++) {
        String threadName = threadGroup.getThreadPoolNamePrefix("partition-operation") + threadId;
        // the normalQueue will be a blocking queue. We don't want to idle, because there are many operation threads.
        MPSCQueue<Object> normalQueue = new MPSCQueue<Object>(null);
        OperationQueue operationQueue = new DefaultOperationQueue(normalQueue, new ConcurrentLinkedQueue<Object>());
        PartitionOperationThread partitionThread = new PartitionOperationThread(threadName, threadId, operationQueue, logger, threadGroup, nodeExtension, partitionOperationRunners);
        threads[threadId] = partitionThread;
        normalQueue.setConsumerThread(partitionThread);
    }
    // we need to assign the PartitionOperationThreads to all OperationRunners they own
    for (int partitionId = 0; partitionId < partitionOperationRunners.length; partitionId++) {
        int threadId = getPartitionThreadId(partitionId, threadCount);
        Thread thread = threads[threadId];
        OperationRunner runner = partitionOperationRunners[partitionId];
        runner.setCurrentThread(thread);
    }
    return threads;
}
Also used : MPSCQueue(com.hazelcast.internal.util.concurrent.MPSCQueue) OperationRunner(com.hazelcast.spi.impl.operationexecutor.OperationRunner) OperationHostileThread(com.hazelcast.spi.impl.operationexecutor.OperationHostileThread)

Aggregations

MPSCQueue (com.hazelcast.internal.util.concurrent.MPSCQueue)1 OperationHostileThread (com.hazelcast.spi.impl.operationexecutor.OperationHostileThread)1 OperationRunner (com.hazelcast.spi.impl.operationexecutor.OperationRunner)1