Suffering to understand Threading

[cross-posted, please don't ban me, I apologize if that's prohibited] Heyy guys! I hope y'all doing great. lets clear some concepts today (to me). This is from Oracle javase jls specs:
While most of the discussion in the preceding chapters is concerned only with the behavior of code as executed a single statement or expression at a time, that is, by a single thread, the Java Virtual Machine can support many threads of execution at once.
While most of the discussion in the preceding chapters is concerned only with the behavior of code as executed a single statement or expression at a time, that is, by a single thread, the Java Virtual Machine can support many threads of execution at once.
So, our systems have a cpu technically it's just one, but using software we have made it powerful by designing cores and threads. one core (is like one person) has two threads (like his hands), in this way we generally have 8 cores 16 threads (or something). Why two threads not three for a core? Cause each core runs independent from each other at the very same time. Context switching is done between threads of a core and not between cores. (1) Am I correct til here? Its practically observed switching between two threads is more optimized and performant in regular PCs (regular users systems) than more threads (though some more powerful systems for other tasks idk have more threads.. I only got to know the basics). (2) Am I correct? Even a simple hello-world program is multi-threaded. (3) some java teacher told me, there are approx 35 threads java runs in background while the main thread you think is only running. for example, a thread for garbage collection, etc. Am I correct until here? (4) If I make twenty threads in my java program and my system cpu is r5 5500u (hexa core) how does this threads system looks like? each of my java program's thread would be assigned to each physical thread and some would be reassigned to existing threads? or just a single thread would be assigned to all threads (or all threads would be assigned to single physical thread) and it will context switch between all java program threads? [THIS IS THE PART I'M CONFUSED FOR A LONG TIME AND FOR THE MOST. ]
1 Reply
JavaBot
JavaBotβ€’6mo ago
βŒ› This post has been reserved for your question.
Hey @πŒ‹! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. πŸ’€ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?