90 How to Develop Deadlock Scenario in Java by Using Join() in Java?

Code :

public class Test  extends Thread
{
static Thread mt = null; // Main Thread 

@Override
public void run()
{
System.out.println("run: "+Thread.currentThread().getName());

try
{
mt.join();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
for(int i=1;i<=10;i++)
{
System.out.println("run: "+Thread.currentThread().getName());
}
}


public static void main(String args[]) throws InterruptedException 
{
Test t = new Test();

System.out.println("main: "+Thread.currentThread().getName());

t.setName(" CodingAtharva ");
mt = Thread.currentThread(); // main thread 
t.start();

t.join();
for(int i =1;i<=10;i++)
{
System.out.println("main: "+Thread.currentThread().getName());
}
}
}




Output:






Previous
Next Post »