This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Basic thread use Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Basic thread use" Watch "Basic thread use" New topic
Author

Basic thread use

Krep Lock
Ranch Hand

Joined: Sep 19, 2006
Posts: 43
Looking thru some source code I ran across this:



1) does new Thread(this) "fork" the process that's running main() and give the spawned copy to aLoop? Is this typical usage for a simple process that a programmer doesn't want to prepare in a separate class?

2) aLoop.start() looks for a run() method and begins a stack with that, right?
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

does new Thread(this) "fork" the process that's running main() and give the spawned copy to aLoop? Is this typical usage for a simple process

The actual thread will only be created after start() is invoked. new Thread() is specifying where run() is implemented.
You will do this if you want to keep main() and run() running concurrently(i.e. in two different threads).
[ January 15, 2008: Message edited by: Abhinav Srivastava ]
 
wood burning stoves
 
subject: Basic thread use