Search code examples
javaapache-commons-math

Apache Commons Math: where are the values for SummaryStatistics stored?


I am using Apache Commons Math in my web application. I need to use this class:

SummaryStatistics

However, I am puzzled by this description:

Computes summary statistics for a stream of data values added using the addValue method. The data values are not stored in memory, so this class can be used to compute statistics for very large data streams.

http://commons.apache.org/proper/commons-math/javadocs/api-3.3/org/apache/commons/math3/stat/descriptive/SummaryStatistics.html

If the values are not stored in memory, where are they stored? On disks? If on disks, what about the file names? Can someone shed light on this? I would also like to know whether SummaryStatistics supports mutli-threads.

This is important to me because a web application allows multi-thread requests and I need to make sure one person's request does not overwrite the summary statistics for another person.


Solution

  • They're not stored anywhere. The class only maintains the minimum summary values it needs, which are the sum, sum of squares, min, max, and a few more values. If in doubt, you can always check out the source code.

    Per thread-safety, the JavaDoc specifically says:

    This class is not thread-safe. Use SynchronizedSummaryStatistics if concurrent access from multiple threads is required.