Called by only same partition thread. So there is no synchronization and visibility problem.
359977
@Override
    public void setEntryCounting(boolean enable) {
        if (enable) {
            if (!entryCountingEnable) {
                // It was disable before but now it will be enable.
                // Therefore, we increase the entry count as size of records.
                cacheContext.increaseEntryCount(size());
            }
        } else {
            if (entryCountingEnable) {
                // It was enable before but now it will be disable.
                // Therefore, we decrease the entry count as size of records.
                cacheContext.decreaseEntryCount(size());
            }
        }
        this.entryCountingEnable = enable;
    }
1147941
public synchronized boolean sync() {
		if (!validState) {
			throw new InvalidStateException();
		}
		try {
			fc.force(false);
			return true;
		} catch (Exception e) {
			log.error("Exception in sync()", e);
		}
		return false;
	}
517611
@SuppressWarnings("checkstyle:npathcomplexity")
    void publishPartitionRuntimeState() {
        if (!partitionStateManager.isInitialized()) {
            // do not send partition state until initialized!
            return;
        }

        if (!node.isMaster()) {
            return;
        }

        if (!areMigrationTasksAllowed()) {
            // migration is disabled because of a member leave, wait till enabled!
            return;
        }

        PartitionRuntimeState partitionState = createPartitionStateInternal();
        if (partitionState == null) {
            return;
        }

        if (logger.isFineEnabled()) {
            logger.fine("Publishing partition state, version: " + partitionState.getVersion());
        }

        PartitionStateOperation op = new PartitionStateOperation(partitionState, false);
        OperationService operationService = nodeEngine.getOperationService();
        Collection<Member> members = node.clusterService.getMembers();
        for (Member member : members) {
            if (!member.localMember()) {
                try {
                    operationService.send(op, member.getAddress());
                } catch (Exception e) {
                    logger.finest(e);
                }
            }
        }
    }
1274855
protected void syncCompactor() {
        ConcurrentLinkedQueue<Segment> queue = _compactor.getCompactedQueue();
        while(!queue.isEmpty()) {
            Segment seg = queue.remove();
            consumeCompactionBatches();
            _compactor.getFreeQueue().offer(seg);
        }
        
        consumeCompactionBatches();
    }
1068144
void lockBucketsRead(long i1, long i2) {
		int bucket1LockIdx = getBucketLock(i1);
		int bucket2LockIdx = getBucketLock(i2);
		// always lock segments in same order to avoid deadlocks
		if (bucket1LockIdx < bucket2LockIdx) {
			lockAry[bucket1LockIdx].readLock();
			lockAry[bucket2LockIdx].readLock();
		} else if (bucket1LockIdx > bucket2LockIdx) {
			lockAry[bucket2LockIdx].readLock();
			lockAry[bucket1LockIdx].readLock();
		}
		// if we get here both indexes are on same segment so only lock once!!!
		else {
			lockAry[bucket1LockIdx].readLock();
		}
	}
1179847
@Override
  public void resync() {
    lock.writeLock().lock();
    try {
      if (this.knownObjects == null) {
        return;
      }

      List<String> keys = this.knownObjects.listKeys();
      for (String key : keys) {
        syncKeyLocked(key);
      }
    } finally {
      lock.writeLock().unlock();
    }
  }
935296
private void synchronizeBucketsWithHDD() {
        int synchronizedBuckets = 0;
        // run over all buckets
        for (int i = 0; i < numberOfBuckets; i++) {
            Bucket<Data> oldBucket = bucketContainer.getBucket(i);

            // if the bucket is empty, then do nothing
            if (oldBucket.elementsInBucket == 0) {
                synchronizedBuckets++;
                continue;
            }

            /* ***** TESTING PURPOSE ****** */
            if (DynamicMemoryAllocater.INSTANCES[gp.instanceID].getFreeMemory() == 0) {
                log.info("No memory free, theoretically I must force synchronization");
            }
            /* **************************** */

            long elapsedTime = System.currentTimeMillis() - oldBucket.getCreationTime();
            // if the bucket is full, or the bucket is longer then max bucket storage time within the BucketContainer,
            // or the shutdown was initiated, then try to synchronize the buckets
            // At this point we prevent starvation of one bucket if it not filled for a long period of time.
            if (oldBucket.elementsInBucket >= gp.MIN_ELEMENT_IN_BUCKET_BEFORE_SYNC ||
                    // TODO What do we do if more than one DynamicMemoryAllocator exist???
                    DynamicMemoryAllocater.INSTANCES[gp.instanceID].getFreeMemory() == 0 ||
                    // DynamicMemoryAllocater.INSTANCE.getFreeMemory() == 0 ||
                    elapsedTime > maxBucketStorageTime ||
                    shutDownInitiated ||
                    forceInitiated) {
                if (!startNewThread(i)) {
                    sleep();
                }
            }
        }

        if (shutDownInitiated) {
            log.info("{} of {} buckets were synchronized.", synchronizedBuckets, bucketContainer.getNumberOfBuckets());
        }

        // if the queue is not full try to fill it
        if (bufferThreads.getQueue().size() < bufferThreads.getMaximumPoolSize()) {
            int bucketId = getLargestBucketId();
            if (bucketId != -1) {
                Bucket<Data> pointer = bucketContainer.getBucket(bucketId);
                boolean threadStarted = false;
                if (DynamicMemoryAllocater.INSTANCES[gp.instanceID].getFreeMemory() == 0 ||
                        pointer.elementsInBucket >= gp.MIN_ELEMENT_IN_BUCKET_BEFORE_SYNC ||
                        forceInitiated) {
                    threadStarted = startNewThread(bucketId);
                }

                if (!threadStarted) {
                    sleep();
                }
            }
        }
    }
1295960
private void ensureWatchThreadRunning() {
		if (!threadRunning) {
			thread = new Thread(watchThread);
			thread.setDaemon(true);
			thread.start();
			watchThread.setThread(thread);
			watchThread.updateName();
			threadRunning = true;
		}
	}
1006522
public synchronized void lockExclusive()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "lockExclusive", this);

        boolean interrupted = false;

        // If another thread is attempting to lock exclusive,
        // wait for it to finish first.
        while (!tryLockExclusive())
        {
            try
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Waiting to get exclusive lock");
                wait(1000);
            }
            catch (InterruptedException e)
            {
                // No FFDC code needed
                interrupted = true;
            }
        }

            // Wait for existing locks to be released
        while (iLockCount > 0)
        {
            try
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Waiting for lock count to reach 0 " + iLockCount);
                wait(1000);
            }
            catch (InterruptedException e)
            {
                // No FFDC code needed
                interrupted = true;
            }
        }

        if (interrupted)
        {
            Thread.currentThread().interrupt();
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "lockExclusive");
    }
936379
public SyncLazyFuture<X> withRunningThread() {
        if (state != null) return this;
        Thread thread = new Thread(SyncLazyFuture.this.getClass().getName() + ".withRunningThread") {
            @Override
            public void run() {
                try {
                    SyncLazyFuture.this.internalCalc();
                } catch (ExecutionException | InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        thread.start();
        return this;
    }
1193102
public final void run() {
        int partitionCount = partitionService.getPartitionCount();
        latch = new CountDownLatch(partitionCount);

        for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
            operationExecutor.execute(new CollectContainerRunnable(partitionId));
        }

        try {
            latch.await();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
728806
private synchronized void onStateChange(PartitionId partitionId, PrimitiveState state) {
    states.put(partitionId, state);
    switch (state) {
      case CONNECTED:
        if (this.state != PrimitiveState.CONNECTED && !states.containsValue(PrimitiveState.SUSPENDED) && !states.containsValue(PrimitiveState.CLOSED)) {
          this.state = PrimitiveState.CONNECTED;
          stateChangeListeners.forEach(l -> l.accept(PrimitiveState.CONNECTED));
        }
        break;
      case SUSPENDED:
        if (this.state == PrimitiveState.CONNECTED) {
          this.state = PrimitiveState.SUSPENDED;
          stateChangeListeners.forEach(l -> l.accept(PrimitiveState.SUSPENDED));
        }
        break;
      case CLOSED:
        if (this.state != PrimitiveState.CLOSED) {
          this.state = PrimitiveState.CLOSED;
          stateChangeListeners.forEach(l -> l.accept(PrimitiveState.CLOSED));
        }
        break;
    }
  }
243739
@Override
    public void run() {
        try {
            VoltTable partitionKeys = null;
            partitionKeys = m_client.callProcedure("@GetPartitionKeys", "INTEGER").getResults()[0];

            while (partitionKeys.advanceRow()) {
                m_client.callProcedure(new NullCallback(), "DeleteOldAdRequests",
                        partitionKeys.getLong("PARTITION_KEY"),
                        m_expiredAgeInSeconds);
            }

            m_client.callProcedure(new NullCallback(), "DeleteExpiredBids");
        }
        catch (IOException | ProcCallException ex) {
            ex.printStackTrace();
        }
    }
210726
def _worker_thread_transfer(self):
        # type: (SyncCopy) -> None
        
        while not self.termination_check:
            try:
                sd = self._transfer_queue.get(block=False, timeout=0.1)
            except queue.Empty:
                continue
            try:
                self._process_synccopy_descriptor(sd)
            except Exception as e:
                with self._transfer_lock:
                    self._exceptions.append(e)
1302389
public static boolean existsBegunTxOnThread() {
        final Stack<BegunTx<?>> stack = threadLocal.get();
        return stack != null ? !stack.isEmpty() : false;
    }
70936
private void checkSystemInput()
        throws IOException
    {
        while ( System.in.available() > 0 )
        {
            int input = System.in.read();
            if ( input >= 0 )
            {
                char c = (char) input;
                if ( c == '\n' )
                {
                    synchronized ( lock )
                    {
                        finished = true;
                        lock.notifyAll();
                    }
                }
            }
            else
            {
                synchronized ( lock )
                {
                    finished = true;
                    lock.notifyAll();
                }
            }
        }
    }
267207
@Override
	public void write(DataOutput out) throws IOException {
		out.writeInt(this.partitionNumber);
		out.writeInt(this.totalNumberOfPartitions);
	}