wood burning stoves*
The moose likes Threads and Synchronization and the fly likes How do threads work in a regular program ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "How do threads work in a regular program ?" Watch "How do threads work in a regular program ?" New topic
Author

How do threads work in a regular program ?

Lee Sigauke
Ranch Hand

Joined: May 16, 2012
Posts: 30
Hi,

I have just started working with threads and I have a question: here's a scenario

If I have a program with Class A which has a main method, in this main method an instance of Class B is created and class B does "something". My question is if I run class A and and an instance of class B is made, would they be running on the same thread or on different threads ?
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2274
    
  28

In Java, if one method calls another method, the callee and caller execute on the same thread. To run code in a differrent thread, you will have to use the Java threading APi.
Lee Sigauke
Ranch Hand

Joined: May 16, 2012
Posts: 30
Jayesh A Lalwani wrote:In Java, if one method calls another method, the callee and caller execute on the same thread. To run code in a differrent thread, you will have to use the Java threading APi.


Thanks


 
Don't get me started about those stupid light bulbs.
 
subject: How do threads work in a regular program ?
 
Similar Threads
Please clarify why the following code works - Method Local Inner classes
Thread question: extending Thread class and start() 2 instances ?
instanceof doubt
Programming to Interfaces
threads