Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
49 lines (43 loc) · 1.13 KB

File metadata and controls

49 lines (43 loc) · 1.13 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Thread1 extends Thread
{
public void run()
{
for(int i=0;i<5;i++)
System.out.println("Thread1");
}
}
class Thread2 extends Thread
{
static Thread t_hold_1;
public void run() {
try
{
t_hold_1.join();//as t_hold_1 contain thread 1
}
catch(Exception e)
{
}
for (int i = 0; i < 5; i++)
System.out.println("Thread2");
}
}
/**
*Here main thread is waiting for Thread2 to execute by calling t2.join() and thread2 is waiting
for Thread1 to execute by calling t_hold_1.join() as t_hold_1 refer Thread1
so 1st Thread1 execute and then Thread2 and then main
*/
class join_method
{
//join method throw InterruptedException which is checked so we must handle it
public static void main(String[] args)throws InterruptedException
{
Thread1 t1=new Thread1();
Thread2.t_hold_1=t1;
Thread2 t2=new Thread2();
t1.start();
t2.start();
t2.join();
for(int i=0;i<5;i++)
System.out.println("main");
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.