public static synchronized RealtimeSegmentStatsHistory deserialzeFrom(File inFile)
      throws IOException, ClassNotFoundException {
    if (inFile.exists()) {
      try (FileInputStream is = new FileInputStream(inFile); ObjectInputStream obis = new CustomObjectInputStream(is)) {
        RealtimeSegmentStatsHistory history = (RealtimeSegmentStatsHistory) (obis.readObject());
        history.normalize();
        return history;
      }
    } else {
      return new RealtimeSegmentStatsHistory(inFile.getAbsolutePath());
    }
  }
@Test
  public void testMultiThreadedUse()
      throws Exception {
    final int numThreads = 8;
    final int numIterations = 10;
    final long avgSleepTimeMs = 300;
    Thread[] threads = new Thread[numThreads];
    final String tmpDir = System.getProperty("java.io.tmpdir");
    File serializedFile = new File(tmpDir, STATS_FILE_NAME);
    FileUtils.deleteQuietly(serializedFile);
    serializedFile.deleteOnExit();
    RealtimeSegmentStatsHistory statsHistory = RealtimeSegmentStatsHistory.deserialzeFrom(serializedFile);

    for (int i = 0; i < numThreads; i++) {
      threads[i] = new Thread(new StatsUpdater(statsHistory, numIterations, avgSleepTimeMs));
      threads[i].start();
    }

    for (int i = 0; i < numThreads; i++) {
      threads[i].join();
    }

    FileUtils.deleteQuietly(serializedFile);
  }