jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Try to understand threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Try to understand threads" Watch "Try to understand threads" New topic

Try to understand threads

cornel jew
Ranch Hand

Joined: Jul 13, 2002
Posts: 37
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.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Have you seen this ?
It gives a good introduction to java threads.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
One normal process can only do one thing at a time.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

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.

Please ignore post, I have no idea what I am talking about.
I agree. Here's the link: http://aspose.com/file-tools
subject: Try to understand threads
It's not a secret anymore!