• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Problem in understanding join()

 
Ranch Hand
Posts: 69
MySQL Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am preparing for SCJP 6.0. I am having a problem in understanding join() method.
Can any body provide a small program demonstrating use of join().
 
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arpit Gadle wrote:Hi,
I am preparing for SCJP 6.0. I am having a problem in understanding join() method.
Can any body provide a small program demonstrating use of join().



The join() method is used to wait for another thread to finish. So, when you call the join() method on a thread object, the method will not return, until the thread represented by the thread object has finished.

I am not sure what "problem in understanding" that you may be having. Or how could an example program can really help more than what I just described. Perhaps you can elaborate the issue that you are having.

Henry
 
Arpit Gadle
Ranch Hand
Posts: 69
MySQL Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am clear with the definition. But was having problem in writing small example which demonstrates how join() actually works. After posting this topic, I tried for a while and wrote a program which actually shows how join() works


What this code does is, it joins the current thread (main) to thread t2. So the current thread will not become runnable until t2 has finihsed.

Where should I place call to join() so that thread t2 can join thread t3.
 
Marshal
Posts: 26909
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want the thread which runs the Job_2 class to wait at some point during that running for t3 to terminate before continuing? Then you would call t3.join() in the Job_2 class.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic