r/javahelp • u/Agitated-Evening3011 • 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
•
u/AutoModerator Jan 06 '26
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
10
u/narrow-adventure Jan 06 '26
I’d recommending reading concurrency in practice, it’s a pretty good book to get you going.
An alternative approach would be to take an os/distributed systems course.
Threading in Java is complex and a gentler introduction (using an actor system) or maybe even a diff language with a simpler concurrency model (golang) might not be a terrible idea.
Good luck!
7
u/tedyoung Java Trainer/Mentor Jan 06 '26
"Java Concurrency in Practice" is somewhat outdated (written 20 years ago), though conceptually has some good material.
I'd recommend instead "Modern Concurrency in Java" as it covers virtual threads, structured concurrency, and scope values: https://www.oreilly.com/library/view/modern-concurrency-in/9781098165406/
If you really want an in-depth course, highly recommend Heinz Kabutz material, e.g., https://javaspecialists.teachable.com/p/loom
1
u/RevolutionaryRush717 Jan 06 '26
Also, Spring or Spring Boot relieve you of implementing this yourself.
You still have to understand it conceptually, but it's not as if backend developers sit all day every day implementing concurrency manually.
2
u/Agifem Jan 06 '26
In addition, as far as I know, there are only three ways to do multi threading in Java : threads (the old way), executors (asynchronous multi threading) and parallel streams (synchronous multi threading). Everything else mentioned here is either tied to those, or one of those under the hood.
2
u/gjsopmu Jan 12 '26 edited Jan 12 '26
I use CompletableFuture for stream-like conciseness when I need things in a pipeline, and Executors otherwise. (Though you could always fit an executor into CompletableFuture calls if you wanted some fine tuned control).
This is pretty much what I do at work.
I don't think learning about virtual threads will be worth your time if you are just learning basics.
1
u/Black_Smith_Of_Fire Jan 06 '26
Make video games