core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/statistic/OPerformanceStatisticManager.java
private void updateDeadThreadsStatistic(Collection<Thread> threadsToRemove) {
    deadThreadsUpdateLock.lock();
    try {
      //we accumulate all statistic in intermediate fields and only then put
      //results in #deadThreadsStatistic field to preserve thread safety features
      final ImmutableStatistic oldDS = deadThreadsStatistic;
      final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
      final Map<String, PerformanceCountersHolder> countersByComponents = new HashMap<>();

      WritCacheCountersHolder writeCacheCountersHolder = null;
      StorageCountersHolder storageCountersHolder = null;
      WALCountersHolder walCountersHolder = null;

      //fetch data from old statistic first
      if (oldDS != null) {
        oldDS.countersHolder.pushData(countersHolder);

        for (Map.Entry<String, PerformanceCountersHolder> oldEntry : oldDS.countersByComponents.entrySet()) {
          final PerformanceCountersHolder holder = oldEntry.getValue().newInstance();
          oldEntry.getValue().pushData(holder);

          countersByComponents.put(oldEntry.getKey(), holder);
        }

        if (oldDS.writCacheCountersHolder != null) {
          writeCacheCountersHolder = new WritCacheCountersHolder();
          oldDS.writCacheCountersHolder.pushData(writeCacheCountersHolder);
        }

        if (oldDS.storageCountersHolder != null) {
          storageCountersHolder = new StorageCountersHolder();
          oldDS.storageCountersHolder.pushData(storageCountersHolder);
        }

        if (oldDS.walCountersHolder != null) {
          walCountersHolder = new WALCountersHolder();
          oldDS.walCountersHolder.pushData(walCountersHolder);
        }
      }

      //remove all threads from active statistic and put all in #deadThreadsStatistic field
      for (Thread deadThread : threadsToRemove) {
        final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = statistics.remove(deadThread);
        if (sessionStoragePerformanceStatistic != null) {
          sessionStoragePerformanceStatistic.pushSystemCounters(countersHolder);
          sessionStoragePerformanceStatistic.pushComponentCounters(countersByComponents);
          writeCacheCountersHolder = sessionStoragePerformanceStatistic.pushWriteCacheCounters(writeCacheCountersHolder);
          storageCountersHolder = sessionStoragePerformanceStatistic.pushStorageCounters(storageCountersHolder);
          walCountersHolder = sessionStoragePerformanceStatistic.pushWALCounters(walCountersHolder);
        }
      }

      deadThreadsStatistic = new ImmutableStatistic(countersHolder, countersByComponents, writeCacheCountersHolder,
          storageCountersHolder, walCountersHolder);
    } finally {
      deadThreadsUpdateLock.unlock();
    }
  }
private void updateDeadThreadsStatistic(Collection<Thread> threadsToRemove) {
    deadThreadsUpdateLock.lock();
    try {
      //we accumulate all statistic in intermediate fields and only then put
      //results in #deadThreadsStatistic field to preserve thread safety features
      final ImmutableStatistic oldDS = deadThreadsStatistic;
      final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
      final Map<String, PerformanceCountersHolder> countersByComponents = new HashMap<>();

      WritCacheCountersHolder writeCacheCountersHolder = null;
      StorageCountersHolder storageCountersHolder = null;
      WALCountersHolder walCountersHolder = null;

      //fetch data from old statistic first
      if (oldDS != null) {
        oldDS.countersHolder.pushData(countersHolder);

        for (Map.Entry<String, PerformanceCountersHolder> oldEntry : oldDS.countersByComponents.entrySet()) {
          final PerformanceCountersHolder holder = oldEntry.getValue().newInstance();
          oldEntry.getValue().pushData(holder);

          countersByComponents.put(oldEntry.getKey(), holder);
        }

        if (oldDS.writCacheCountersHolder != null) {
          writeCacheCountersHolder = new WritCacheCountersHolder();
          oldDS.writCacheCountersHolder.pushData(writeCacheCountersHolder);
        }

        if (oldDS.storageCountersHolder != null) {
          storageCountersHolder = new StorageCountersHolder();
          oldDS.storageCountersHolder.pushData(storageCountersHolder);
        }

        if (oldDS.walCountersHolder != null) {
          walCountersHolder = new WALCountersHolder();
          oldDS.walCountersHolder.pushData(walCountersHolder);
        }
      }

      //remove all threads from active statistic and put all in #deadThreadsStatistic field
      for (Thread deadThread : threadsToRemove) {
        final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = statistics.remove(deadThread);
        if (sessionStoragePerformanceStatistic != null) {
          sessionStoragePerformanceStatistic.pushSystemCounters(countersHolder);
          sessionStoragePerformanceStatistic.pushComponentCounters(countersByComponents);
          writeCacheCountersHolder = sessionStoragePerformanceStatistic.pushWriteCacheCounters(writeCacheCountersHolder);
          storageCountersHolder = sessionStoragePerformanceStatistic.pushStorageCounters(storageCountersHolder);
          walCountersHolder = sessionStoragePerformanceStatistic.pushWALCounters(walCountersHolder);
        }
      }

      deadThreadsStatistic = new ImmutableStatistic(countersHolder, countersByComponents, writeCacheCountersHolder,
          storageCountersHolder, walCountersHolder);
    } finally {
      deadThreadsUpdateLock.unlock();
    }
  }
Removes provided dead threads from {@link #statistics} field and accumulates data from them in {@link #deadThreadsStatistic}.

@param threadsToRemove Dead threads statistic of which should be moved to {@link #deadThreadsStatistic} field.