While using Synchronization my threads are working one after the other , the same happens when i have only one thread which executes the instructions one after the other so what’s the use of creating multiple threads.
class Myclass1 extends Thread
{
public void run()
{
System.out.println("Running in class 1");
}
}
class Myclass2 extends Thread
{
public void run()
{
System.out.println("Running in class 2");
}
}
class Driver
{
synchronized public static void main(String[]args)
{
Myclass1 obj1=new Myclass1();
Myclass2 obj2=new Myclass2();
obj1.start();
obj2.start();
System.out.println("Hello");
}
}
New contributor
Ghayathri_Thangadurai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.