• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

thread join problem statement

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you tell me how the code snippet of the following problem look like....

"You have thread T1, T2 and T3, how will you ensure that thread T2 run after T1 and thread T3 run after T2?"

I have given try to code this...Please tell me whether this is correct or not?


 
Master Rancher
Posts: 5060
81
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, that seems to work.

One has to wonder though, why anyone would ever, ever use threads for such a purpose. I mean, if you just want everything to run sequentially, don't use threads. Easy.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I agree--it will work, but it's a pointless problem statement. Note also that you don't need the t3.join(), since the problem statement says nothing about waiting for T3 to end.

A more reasonable problem statement--one that shows the actual practical use of join(), would be something like: "You have T1, T2, and T3. T1 and T2 can execute concurrently, but T3 has to wait for both of them before it can run." Or even, "You have two threads T1 and T2 that are allowed to run concurrently, but your main thread must wait until they both finish before it can continue with its work."

Go ahead and give one or both of those a try.

What we're modelling with those is something like this: "I want to bake a cake. Joe, you go to the grocery store and get eggs, milk, flour, etc. Mary, you go to the housewares store and get a mixer, measuring cups, and a cake pan. I'll start baking when you both get back." Joe and Mary can do their jobs independently of and in parallel to each other, but I have to wait until they both complete their tasks before I can start doing anything.
 
Rahul Ba
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, It was only interview question. Thanks for help.
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic