Forums Register Login

How do threads work in a regular program ?

+Pie Number of slices to send: Send
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 ?
2
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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


Water! People swim in water! Even tiny ads swim in water:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 700 times.
Similar Threads
Please clarify why the following code works - Method Local Inner classes
Programming to Interfaces
Thread question: extending Thread class and start() 2 instances ?
instanceof doubt
threads
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:37:03.