Monday, March 2, 2015

Java Thread's join() method

Thread's join() method

join() is a non static method, it has three forms one without any argument and one join(long millis) with the long value as a parameter
the time to wait in milliseconds. and the third is with the two parameter join (long millis, int nanos) it takes one more parameter value it represents the nano seconds value. 
means if we use this method then it will wait for the total time millis+nanos seconds.

join() method cause the current running thread to wait until the thread which calles join() on get finished.

Example
class MainThread{
public static void main(String[] box){
Thread th = new Thread();
th.join();
or
th.join(2000);
}
}

Here in this example the current running thread is the main thread. it will wait to go in runnable state until the th thread get finished.
and
same way in case of the th.join(2000), the main thread will wait  2000milli before go into runnable state or we can say main thread will join the th thread for 2000milliseconds
then it will go into the runnable state without worrying about the th thread's state.


Keep Visiting
Write your comment


No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...