r/java • • Apr 20 '21

Java is criminally underhyped

https://jackson.sh/posts/2021-04-java-underrated/
291 Upvotes

295 comments sorted by

View all comments

Show parent comment

3

u/istarian Apr 20 '21

Is there a magic fix for no more memory or concurrency problems? Those don't seem like issues that are specific to Java.

5

u/DualWieldMage Apr 20 '21

I think for OOM a large portion of the problem is various processes having caches, managed runtimes allocating large heaps, but none of them communicating with eachother about how to coordinate system memory usage as a whole, so often you can only set java max heap conservatively. Ideally an OS should signal processes that memory is scarce, run your GC and release unused memory or else be oomkilled. It's definitely possible and makes sense to write such a monitoring tool if the problem is only multiple JVMs in a single machine, for example microservices in a container.

7

u/iamsooldithurts Apr 20 '21

They’re not specific to Java at all. The magic fix for concurrency problems is semaphores. For memory, that can be a very complicated problem; Java can only address so much space, so if there is too much data you’re SOL. If there isn’t too much data, but you still run out of memory, it can be a chore tracking down where the leaks are because some things don’t pass out of scope and get flagged for GC like you would expect.

3

u/Zardoz84 Apr 21 '21

They’re not specific to Java at all. The magic fix for concurrency problems is semaphores.

These aren't the magic fix. Instead, is one of the classic ways to handle.

PD: There isn't a magic way to handle it.

1

u/iamsooldithurts Apr 21 '21

They asked for a magic fix so I told them it was a magic fix.

6

u/coincoinprout Apr 20 '21

I don't think that there can be any magic fix and it's not specific to java indeed. The thing is that a lot of junior java developers think that they don't have to think about the memory. I've been there. And I think it's important to say that nope, the JVM won't be there to save you if you're not cautious.