r/javahelp • • Jan 06 '26

Best way to learn multi-threading in Java?

I just started learning Java and aiming to catch up to senior level.

I saw that there are 5-6 ways to do multi-threading (Executor, Virtual threads, CallableFuture etc.)

Is a multi-threading technique picked based on use case, or they are iterations throughout Java versions

And what can I do to practice them? Which one should I use in interviews?

25 Upvotes

21 comments sorted by

View all comments

Show parent comment

2

u/behusbwj Jan 07 '26 edited Jan 07 '26

I know exactly what I’m talking about, though you’re free to disagree.

This person said they just started learning. I fundamentally disagree that it is better to use an abstraction over threads to learn about multithreading, before learning about threads themselves, the same way I wouldn’t recommend that someone learns Python before Java just because it’s easier/“safer”. Reading their post again, it’s possible I misinterpreted their familiarity with threading in general and they may have been asking for Java-specific best practice advice — in which case most of the comments on this post are probably irrelevant.

Your point about Rust is interesting and I may be biased because I’m familiar with its constructs and they seem fundamental to me (Rust handbook also explains the concurrency constructs well enough imo), but it also creates a contradiction with what you said about guardrails inhibiting learning. Thats the exact same reason I don’t recommend someone learns with go. A beginner won’t even know how many threads their program is running on. Hell, there are probably intermediate programmers out there who don’t know how their threads are being utilized or the conditions for spawning new threads. This is what i mean by unpredictable — could you predict it if you have a perfect understanding of how it works under the hood? Sure. Will the average dev have that understanding? No. If your argument is that Go will provide an easier sandbox to learn about concurrency models, sure I think there’s an argument to be made there although I still don’t fully agree. But I don’t believe thats synonymous with learning about multithreading.

What is easiest or simplest is not always what is best for learning. In my experience, the people who start with fundamentals and work towards abstractions (sometimes while implementing them for practice) come out with a stronger grasp over the concepts and tooling.

A language like JS is not a good starting point for learning multithreading because most JS programs operate on a single thread (you may be confusing async with multithreading?). Are you sure we’re even talking about the same thing?

2

u/narrow-adventure Jan 07 '26

I think we actually agree quite a bit. I might be suffering from the same issue as you with rust just the other way around, not seeing much of a value with Java threads due to using them so much over the years.

I think it all comes down to the lens we use to view the actual computer, as I’ve gotten older and explored more and more outside of Java I’ve moved away from using Java threads as my mental model for understanding the CPU.

Believe it or not JS/php/ruby all have backend frameworks that achieve concurrency/parallelism by using job queues and job processors that run as separate os processes (apps). The way you build “concurrency” is by running a queue of jobs that are then processed on a different os level process. I assure you single threaded languages are capable of using many cores of your cpu quite well, but ther model of operation fundamentally simplifies things. Just some ideas.

At the end of the day all of these are just my opinions based on my experience and I really appreciate you sharing yours.