@Override public int getPartitionThreadId(int partitionId) { return getPartitionThreadId(partitionId, partitionThreads.length); }
@Override public int getPartitionThreadId(int partitionId) { return getPartitionThreadId(partitionId, partitionThreads.length); }
private int nextPartitionId() { for (; ; ) { int partitionId = partitions.nextSetBit(nextPartitionId); if (partitionId == -1) { return -1; } nextPartitionId = partitionId + 1; if (getPartitionThreadId(partitionId, partitionThreadCount) == threadId) { // only selected partitions that belong to the right partition thread. return partitionId; } } } }
private int nextPartitionId() { for (; ; ) { int partitionId = partitions.nextSetBit(nextPartitionId); if (partitionId == -1) { return -1; } nextPartitionId = partitionId + 1; if (getPartitionThreadId(partitionId, partitionThreadCount) == threadId) { // only selected partitions that belong to the right partition thread. return partitionId; } } } }
private PartitionOperationThread[] initPartitionThreads(HazelcastProperties properties, String hzName, NodeExtension nodeExtension, ClassLoader configClassLoader) { int threadCount = properties.getInteger(PARTITION_OPERATION_THREAD_COUNT); if (threadCount <= 0) { // default partition operation thread count int coreSize = RuntimeAvailableProcessors.get(); threadCount = Math.max(2, coreSize); } IdleStrategy idleStrategy = getIdleStrategy(properties, IDLE_STRATEGY); PartitionOperationThread[] threads = new PartitionOperationThread[threadCount]; for (int threadId = 0; threadId < threads.length; threadId++) { String threadName = createThreadPoolName(hzName, "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>(idleStrategy); OperationQueue operationQueue = new OperationQueueImpl(normalQueue, new ConcurrentLinkedQueue<Object>()); PartitionOperationThread partitionThread = new PartitionOperationThread(threadName, threadId, operationQueue, logger, nodeExtension, partitionOperationRunners, configClassLoader); 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; }
private PartitionOperationThread[] initPartitionThreads(HazelcastProperties properties, String hzName, NodeExtension nodeExtension, ClassLoader configClassLoader) { int threadCount = properties.getInteger(PARTITION_OPERATION_THREAD_COUNT); if (threadCount <= 0) { // default partition operation thread count int coreSize = RuntimeAvailableProcessors.get(); threadCount = Math.max(2, coreSize); } IdleStrategy idleStrategy = getIdleStrategy(properties, IDLE_STRATEGY); PartitionOperationThread[] threads = new PartitionOperationThread[threadCount]; for (int threadId = 0; threadId < threads.length; threadId++) { String threadName = createThreadPoolName(hzName, "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>(idleStrategy); OperationQueue operationQueue = new OperationQueueImpl(normalQueue, new ConcurrentLinkedQueue<Object>()); PartitionOperationThread partitionThread = new PartitionOperationThread(threadName, threadId, operationQueue, logger, nodeExtension, partitionOperationRunners, configClassLoader); 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; }