This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

thread Join method

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning threads in java. This is a simple example for Join method
Based on my understanding of the join method, when a Join method is called on a thread t1 the current thread will block its execution untill the thread t1 completes its action. Based on this understanding I have written the following code. But its not working as expected. Kindly correct me If my understanding is wrong. Please find my code below, from the code I have 3 threads t1, t2 & t3. I have started t1 and t2 and then call join on t2 and starting t1. When t2. join is called, I expect thread t1 to wait but its running in parallel.



Ouput:


Running in Thread1 1
Running in Thread2 1
Running in Thread1 2
Running in Thread2 2
Running in Thread1 3
Running in Thread2 3
Running in Thread2 4
Running in Thread1 4
Running in Thread1 5
Running in Thread2 5
Running in Thread3 1
Running in Thread3 2
Running in Thread3 3
Running in Thread3 4
Running in Thread3 5

 
Bartender
Posts: 3681
153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Inmank,

you write:

inmank Kar wrote:(...), from the code I have 3 threads t1, t2 & t3. I have started t1 and t2 and then call join on t2 and starting t1. When t2. join is called, I expect thread t1 to wait but its running in parallel.


Why do you think t1 will be witing for t2 after the call: t2.join()?

The thread that issues "t2.join()" will be waiting. Here, this thread is NOT t1. Which thread is waiting here? t2, t3, or ...?

Greetings,
Piet
 
Hug your destiny! And hug this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!