r/java • u/NotABot1235 • Mar 07 '24
"Java is here to stay": Popular programming language to remain on business hit lists in 2024
r/java • u/NotABot1235 • Mar 07 '24
r/java • u/prisonbird • Dec 19 '22
damn, they are really changed my life.
i was trying to run some custom logic on every line on some big CSV files. tried python dataframes, multiprocessing in python, pyspark. none of them did it in an acceptable time.
then i discovered java streams. i have a workflow that takes 70 minutes with pyspark. it takes 3.5 minutes with java streams.
more people should know about streams.
stream operations are more intuitive than anything i tried. i can make a lot of analysis on our data in record times thanks to streams.
i dont know how java does this.
r/java • u/jumpixel • May 01 '22
r/java • u/chabala • Nov 30 '21
r/java • u/janora • Jun 26 '24
r/java • u/randgalt • Dec 29 '19
https://www.youtube.com/watch?v=te3OU9fxC8U
Very good presentation at a Kotlin conference. The presenter accurately shows what Java will look like in a few years with great detail - including byte code dumps. I think he's trying to show that Kotlin already has many of these features or that it probably will. But, what he's really showing is that Oracle does nearly all of these features better because they can change the JVM and/or just have put more thought into it. My conclusion after watching it is that there's no reason to switch to Kotlin (unless you're doing Android development). In a few years, Java will have all of its features that people are bragging about today and most of them will be better in Java.
r/java • u/GavinRayDev • Jan 16 '23
r/java • u/davidalayachew • Nov 19 '24
First off, apologies for being AWOL. Been (and still am) juggling a lot of emergencies, both work and personal.
My team was in crunch time to respond to a pretty ridiculous client ask. In order to get things in in time, we had to ignore performance, and kind of just took the "shoot first, look later" approach. We got surprisingly lucky, except in one instance where we were using Java Streams.
It was a seemingly simple task -- download a file, split into several files based on an attribute, and then upload those split files to a new location.
But there is one catch -- both the input and output files were larger than the amount of RAM and hard disk available on the machine. Or at least, I was told to operate on that assumption when developing a solution.
No problem, I thought. We can just grab the file in batches and write out the batches.
This worked out great, but the performance was not good enough for what we were doing. In my overworked and rushed mind, I thought it would be a good idea to just turn on parallelism for that stream. That way, we could run N times faster, according to the number of cores on that machine, right?
Before I go any further, this is (more or less) what the stream looked like.
try (final Stream<String> myStream = SomeClass.openStream(someLocation)) {
myStream
.parallel()
//insert some intermediate operations here
.gather(Gatherers.windowFixed(SOME_BATCH_SIZE))
//insert some more intermediate operations here
.forEach(SomeClass::upload)
;
}So, running this sequentially, it worked just fine on both smaller and larger files, albeit, slower than we needed.
So I turned on parallelism, ran it on a smaller file, and the performance was excellent. Exactly what we wanted.
So then I tried running a larger file in parallel.
OutOfMemoryError
I thought, ok, maybe the batch size is too large. Dropped it down to 100k lines (which is tiny in our case).
OutOfMemoryError
Getting frustrated, I dropped my batch size down to 1 single, solitary line.
OutOfMemoryError
Losing my mind, I boiled down my stream to the absolute minimum possible functionality possible to eliminate any chance of outside interference. I ended up with the following stream.
final AtomicLong rowCounter = new AtomicLong();
myStream
.parallel()
//no need to batch because I am literally processing this file each line at a time, albeit, in parallel.
.forEach(eachLine -> {
final long rowCount = rowCounter.getAndIncrement();
if (rowCount % 1_000_000 == 0) { //This will log the 0 value, so I know when it starts.
System.out.println(rowCount);
}
})
;And to be clear, I specifically designed that if statement so that the 0 value would be printed out. I tested it on a small file, and it did exactly that, printing out 0, 1000000, 2000000, etc.
And it worked just fine on both small and large files when running sequentially. And it worked just fine on a small file in parallel too.
Then I tried a larger file in parallel.
OutOfMemoryError
And it didn't even print out the 0. Which means, it didn't even process ANY of the elements AT ALL. It just fetched so much data and then died without hitting any of the pipeline stages.
At this point, I was furious and panicking, so I just turned my original stream sequential and upped my batch size to a much larger number (but still within our RAM requirements). This ended up speeding up performance pretty well for us because we made fewer (but larger) uploads. Which is not surprising -- each upload has to go through that whole connection process, and thus, we are paying a tax for each upload we do.
Still, this just barely met our performance needs, and my boss told me to ship it.
Weeks later, when things finally calmed down enough that I could breathe, I went onto the mailing list to figure out what on earth was happening with my stream.
Here is the start of the mailing list discussion.
https://mail.openjdk.org/pipermail/core-libs-dev/2024-November/134508.html
As it turns out, when a stream turns parallel, the intermediate and terminal operations you do on that stream will decide the fetching behaviour the stream uses on the source.
In our case, that meant that, if MY parallel stream used the forEach terminal operation, then the stream decides that the smartest thing to do to speed up performance is to fetch the entire dataset ahead of time and store it into an internal buffer in RAM before doing ANY PROCESSING WHATSOEVER. Resulting in an OutOfMemoryError.
And to be fair, that is not stupid at all. It makes good sense from a performance stand point. But it makes things risky from a memory standpoint.
Anyways, this is a very sharp and painful corner about parallel streams that i did not know about, so I wanted to bring it up here in case it would be useful for folks. I intend to also make a StackOverflow post to explain this in better detail.
Finally, as a silver-lining, Viktor Klang let me know that, a .gather() immediately followed by a .collect(), is immune to this pre-fetching behaviour mentioned above. Therefore, I could just create a custom Collector that does what I was doing in my forEach(). Doing it that way, I could run things in parallel safely without any fear of the dreaded OutOfMemoryError.
(and tbh, forEach() wasn't really the best idea for that operation). You can read more about it in the mailing list link above.
Please let me know if there are any questions, comments, or concerns.
EDIT -- Some minor clarifications. There are 2 issues interleaved here that makes it difficult to track the error.
Gatherers don't (currently) play well with some of the other terminal operations when running in parallel.
Iterators are parallel-unfriendly when operatiing as a stream source.
When I tried to boil things down to the simplistic scenario in my code above, I was no longer afflicted by problem 1, but was now afflicted by problem 2. My stream source was the source of the problem in that completely boiled down scenario.
Now that said, that only makes this problem less likely to occur than it appears. The simple reality is, it worked when running sequentially, but failed when running in parallel. And the only way I could find out that my stream source was "bad" was by diving into all sorts of libraries that create my stream. It wasn't until then that I realized the danger I was in.
r/java • u/AppleTrees2 • Feb 21 '21
I remember when I first started my first job, straight out of university, full of theoretical knowledge, I disliked my java job, mainly because it wasn't as fulfilling as the things I expected, and also because I used a older versions of java.
Now as years pass, and I had to take on a more full-stack role, and started using javascript, and node.js, and noticing the mistakes they made, I started appreciating java more, not necessarily as a language, but also as the whole package, from IDE, build system, ecosystem etc.
Myself from many years ago would be shocked to say that today I'd consider java a good language for many types of personal projects, other than really low-end stuff, and gamedev, I end up using java a lot, it's just so much faster to do stuff in it.
r/java • u/psychologicalX • Mar 05 '18
r/java • u/davidalayachew • Jul 06 '24
Putting it as a text post because Reddit seems to have blocked LinkedIn posts with their spam filter. Weird that the /r/programming post made it through without any trouble.
r/java • u/henk53 • May 10 '22
r/java • u/pron98 • May 06 '21
r/java • u/brogrammer2018 • Jan 04 '18
r/java • u/meotau • Jul 30 '18
r/java • u/rifain • Jul 13 '25
I'll describe my situation. I am in a project where we are using hibernate. I don't harbor any particular feeling towards it but I know that hibernate is more complex than it looks.
This is a typical situation I have already met where developpers trust blindly hibernate. Everything is in lazy loading (because it's more "performant") and that's it. They never look at the database side of things. As expected, the application is slow, and the database is blamed.
So one day I made a demo. I enabled the hibernate logging and I showed them the sql output. It was a mess. Some screen that could take at most 3 or 4 queries generated hundreds of queries, sometimes thousands.
The project manager has second thoughts about hibernate but I explained that it's manageable (there are several ways to fix that), but that the developers need to be cautious and control the sql output. They all agreed, but still, they don't give a damn.
The manager is frustrated, although we improved some calls. I am at a point where I wouldn't recommand hibernate in any project. Not because of the tool, but because of the laziness hibernate brings in the developers. There are tools like jooq or MyBatis which give a finer control and view over sql that I want to explore from now on.
r/java • u/Adventurous-Pin6443 • Jun 19 '25
Old news. We have open-sourced Carrot Cache, a Java-native in-memory cache designed for extreme memory efficiency. In our benchmarks, it uses 2–6× less RAM than EHCache or Caffeine.
It’s fully off-heap, supports SSDs, requires no GC tuning and supports entry eviction, expiration. We’re sharing it under the Apache 2.0 license.
Would love feedback from the Java community — especially if you’ve ever hit memory walls with existing caches.
r/java • u/SuperCoder79 • Apr 28 '22
Hello! Today I'm happy to announce the release of a project that me and my friends have been working on over the course of the last year, Quiltflower! Originally intended just for use with the QuiltMC toolchain with Minecraft, Quiltflower quickly expanded to be a general purpose java decompiler aiming to create code that is as accurate and clean as possible. If the name sounds familiar it's because Quiltflower is a fork of Fernflower, the (in)famous decompiler that was developed by Stiver, maintained by Jetbrains, and became the default decompiler in Intellij IDEA. Fernflower also quickly found its way into many other tools. After many frustrations with it myself with its decompiled code structuring and quality I decided to do something about it, and here we are! Over the past year, Quiltflower has added support for features such as modern string concatenation, a code formatter, sealed classes, pattern matching, switch expressions, try-with-resources, and more. Quiltflower also focuses on the code quality of the decompiled output, and takes readability very seriously. We'd greatly appreciate it if you'd give it a try, with our Intellij Plugin, as a standalone jar, or on our maven. While it has come a long way it's still a work in progress, and feedback can be reported on our issue tracker.
Here's a comparison of Fernflower and Quiltflower's output.
I'd also like to thank the MinecraftForge Team for creating ForgeFlower, the fork that QuiltFlower was based on, and Lee Benfield for creating CFR and it's truly incredible test suite.
r/java • u/hittoyand • Nov 03 '24
r/java • u/RockLeeOfTheMounties • Jan 09 '20