I have a fixed size blocking queue A which contains Customer object. The queue size is 1000.
public class Customer {
private final String accountId;
private Double value = null;
private Customer(final String accountId, Double value) {
this.accountId = accountId;
this.value= value;
}
}
There are two threads running. The main thread is putting this Customer object in queue A and there is another thread which is polling the customer object from the queue.
The second thread needs to process these customers objects in a hashmap Map where the key is the accountId and value is a record object that.
public class Record {
List<Double> values;
List<Double> count;
}
here list values should contain all the unique values and list of count should contain the frequency of the value.
For example :
Queue A contains the following customer object
{"111", 8.0}
{"111", 8.0}
{"111", 9.0}
{"111", 9.0}
{"111", 9.0}
{"111", 10.0}
{"222", 2.0}
{"222", 3.0}
{"222", 3.0}
The expected output is
{"111", Record {[8.0, 9.0, 10.0], [2.0, 3.0, 1.0]}}
{"222" Record {[2.0, 3.0], [1.0, 2.0]}
The way I was implementing it was adding all the values in a list first, the counting the frequency of occurrence of all elements in the list and removing the duplicate from the list. But this is not good solution as it's occupying lot of memory. Could you please suggest me optimized way of doing this. Thanks