So I’m trying to find out a bit about Threads and everywhere its said that every process has at least one thread. That would mean if I only have a main class it would be a thread, wouldn’t it?
But: I thought the class becomes a thread by extending Thread.
So how come every process has a Thread, when I do not extend it in main?
Having more than one Thread only makes the process faster, if I use different resources, which can be used at the same time… like if I read in input from user one thread can wait for the user to type in and press enter, while another can work with the last input and so on.. right?
But if I want to calculate a bunch of equations.. it would NOT be faster with more than one thread, because they cannot calculate at the same time anyway (if I do not have several processors..)
Can someone clear things up for me? I tried to read a lot about this, but everyone just use the same words and that just doesn’t help me with my problem!
A class isn’t a thread. They’re separate concepts. Threads execute code; there’s no way code can execute without being executed by some thread or other.
You create new threads using the
Threadclass (or using another class to do it for you) but a thread of execution is separate to theThreadclass itself. AThreadobject is just a representation of the thread of execution. The JVM itself starts up threads (including the “main” thread) in order to execute code.It sounds like you’re mostly right about the point of threads and when they can be useful… although these days it’s pretty rare to be running on a machine with only one processor.