It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Whats join in Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Whats join in Thread" Watch "Whats join in Thread" New topic
Author

Whats join in Thread

Aftab Ahmed
Ranch Hand

Joined: Nov 22, 2000
Posts: 42
hi frnds,
can any buddy give complete detail of join method in Thread Object.
thanx

Keep Simlling
Bharatesh H Kakamari
Ranch Hand

Joined: Nov 09, 2000
Posts: 198
join method belongs to thread class.
It is overloaded in the following way:
i) void join()
ii) void join(long millis)
iii) void join(long millis, int nanos)
Invoking a join method in a thread means that this thread will wait for all other threads to complete their task. For example main method (main thread) may create n number of threads. When the tasks of the main thread completes it exits without waiting for the threads it created. This is the normal behavoir. Providing join in the main thread makes this thread to wait until other threads finish their task.
HTH
Prasad Ballari
Ranch Hand

Joined: Sep 23, 2000
Posts: 149
Bharatesh,
I am just editing your message:
"Invoking a join method in a thread means that this thread will wait for all other "child" threads to complete their task. For example main method (main thread)("main thread is daemon thread" which will go to dead state only if there are no more active threads) may create n number of threads. When the tasks of the main thread completes it exits without waiting for the threads it created. This is the normal behavoir. Providing join in the main thread makes this thread to wait until other child threads finish their task."
Regards
Prasad


[This message has been edited by Prasad Ballari (edited November 23, 2000).]
Govinda
Greenhorn

Joined: Nov 20, 2000
Posts: 29
whaaaaaaaaaaaaat!!!???/
prasad bellari ,who told you that main thread is a Daemon Thread ???
[This message has been edited by Govinda (edited November 23, 2000).]
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1836
Hi,
Here's a small example of the join method of Thread class

class demo
{
public static void main(String[] args)
{
xclass x=new xclass();
Thread thread2=new Thread(x);
thread2.start();
try{
thread2.join();// current thread will wait till run of thread2 is over
}
catch(Exception e){}
System.out.println("Done");
}
}
class xclass implements Runnable
{public void run(){
int i;
for (i=0;i<10000 ;i++ )
{System.out.println(i);
}
}}

[This message has been edited by Rahul Mahindrakar (edited November 23, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Whats join in Thread
 
Similar Threads
Ganguli Vs Chappel controversy : What is your prediction ?
Stopping a thread
concept of join in thread
WA #1.....word association
SCJWSD online Group study