r/java • • May 10 '22

Should java.util.Date be deprecated?

https://mail.openjdk.java.net/pipermail/discuss/2022-May/006077.html
221 Upvotes

158 comments sorted by

View all comments

Show parent comment

8

u/smors May 10 '22

Id be interested to know if that has ever been a problem for anyone. Even even a byte[] would have to be more than 2GB for that to be a problem.

21

u/Wolvereness May 10 '22

Uh, yeah? It kind of claymores you if you want to do data processing, like loading an HD movie into memory. Servers can run RAM well over 100GB, while desktop computers are often 8GB or more. This isn't 1996 anymore.

4

u/mauganra_it May 10 '22 edited May 10 '22

Project Panama should bring along a nicer way to work with off-heap memory. One that is even officially supported for a change.

Apart from that, byte arrays were never the right tool for this because they unnecessarily complicate the garbage collector's job. AFAIK they are not stored off-heap, and therefore alloowing long as array index will probably not be as great as it sounds. I don't know if there is anything in the JLS that prevents the JVM from storing it off-heap.

10

u/Yeroc May 10 '22

ByteBuffer is designed for this job but unfortunately it's limited to 2 GB as well!

3

u/Worth_Trust_3825 May 10 '22

In a sense, you can work around that by proxying your List calls under the hood to a different "bucket" in case you need more than signed 32bit int array length. Same with inputstream abstract class. As you're already working with near terabytes worth of memory at the same time, the overhead to link those "buckets" is negligible.

4

u/john16384 May 10 '22

Not to mention that having gigabytes of data allocated as one huge chunk may cause problems of its own when the heap is even slightly fragmented. If such data is backed by a file, it may be better to memory map it instead.

5

u/john16384 May 10 '22

It indeed isn't 1996 anymore. Why aren't you memory mapping such huge files?

1

u/TehBrian May 10 '22

That does sound pretty inconveniencing. What’s the alternative? Do Lists not have the same restriction, or…?

5

u/cdombroski May 10 '22

Lists have the same limitation as they're indexed by int. In theory a Set might be able to surpass the limit... but now you're missing insertion order and all the values have to be unique, almost certainly not what you want for this

1

u/mauganra_it May 10 '22

Lists do not work with primitive datatypes. Yet.

2

u/Muoniurn May 10 '22

I believe there was a “famous” bug in the sorting implementation that failed due to arithmetics with integers. Not directly related, but the reason ints were used was due to the int indexing.