I have a sensor which receives data at random times at a high frequency and I need a rolling time series window of a specified size (e.g 60 data points) at a specified frequency (e.g 1 data point per second).
The sampled value should be the latest value read from the sensor (i.e all other values between the reads should be discarded).
I assume some sort of producer-consumer pattern is suitable here, but since I lack experience with concurrency I am struggling with a proper and efficient implementation.
When I want to consume all data produced I understand that the ArrayBlockingQueue
is a good data structure to choose, but in this case I only want to consume the latest value produced (or if no value is produced, the value of the prior period), and this at exactly a specified frequency (e.g once per second).