Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

can join() be used between Peer threads

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is one question that has baffled me. As i read through the topics on thread I came to understand that join() method to some extent can be used to sequence the order in which the threads are executing
Now I have one question:
In all the code examples provided uptill now the thread spawning another thread calls the join method on the spawned thread. By this i mean
If thread A creates thread B then A calls b.wait() where b is an object of type thread B. So as of now we have join() helping us to allow the parent wait for the child.
But what if I have two peer threads let's say C and D both spawned by the main thread; but I want thread D to execute only after thread C executes.
How do i accomplish that.
Please help me out here. I have written a sample code for the same but i dont seem to get that right. Please help me out. I can post the code if needed

Thanks in advance
Prahalad
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- The thread that should only start after another thread has to have a reference to the thread it should join.
- If the other thread is not yet alive, a call to join will not cause the first thread to wait (NEW state has to be taken into account).

I think the following class should do what you described:

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic