• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Try to understand threads

 
cornel jew
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
A simple question which bothers me.
When a thread is created and started in main, does the two threads share the procesor, or does the one wait for the other to finish before it can run.
Is the processor like say split in two if i can use the terminology so that the two threads can run at the same time.
Just wondering.
Hope you understand my question.
Thanks for any answers.
Cornel
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you seen this ?
It gives a good introduction to java threads.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One normal process can only do one thing at a time.
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most machines only have one cpu. In that case every thread (aka process) shares the cpu. In the event that the machine has more than one cpu than you might have different threads running on different cpus at the same time.
I don't know if any of that is important when thinking about threads. The benefit of using threads is that it frees up the cpu from having to sequentially execute all of your code. Which in many cases (but not all) can speed up your program. Than there are also some problems which you can't really solve without having some sort of multi-process ability.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic