Hi,
I am writing a program which works with epoch timestamps out of log files. There is a part of the program in which I am iterating through these timestamps, trying to find the first after a threshold, and since it is very important that there aren't any number representation errors, I would like to store the time read in as a BigDecimal object, initialised from the
string in the file (unfortunately I can't use longs to store the time as the format of the string is <digits>.<digits> seconds).
The immutability of BigDecimal objects poses a problem, as, since I am checking each timestamp in turn and there is very little logic in each loop iteration, I would be creating a huge number of BigDecimal objects, and the program may in the future be extended for concurrent execution, such that many files would be processed at once. I'm therefore worried about the memory footprint of the method described.
I was initially wondering if there's a way to deallocate memory for objects in
Java, such that I could deallocate the previous BigDecimal object each time I created a new one, but there doesn't seem to be. The closest I seem to be able to get is being able to request garbage collection, but will that be fast enough to offset the rate at which new BigDecimal objects are being created, and is it a bad idea to perform the request as often as in a for loop which is executed hundreds or thousands of times each second?
If anyone has any suggestions for reading in the time from the file so that it can be compared without loss of accuracy due to number representation I would be only too happy to receive them
Many thanks.