public class Test1 extends
Thread {
public void run(){
display();
}
synchronized static void display(){//synchronized static
for(int i=0;i<7;i++){
System.out.println(Thread.currentThread().getName()+" "+i+" ");
}
System.out.println("--------");
}
public static void main(
String s[]){
Test1 t1=new Test1();
Test1 t2=new Test1();
Test1 t3=new Test1();
Test1 t4=new Test1();
Test1 t5=new Test1();
t1.setName("T1: ");
t2.setName("T2: ");
t3.setName("T3: ");
t4.setName("T4: ");
t5.setName("T5: ");
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
System.out.println("Main Thread Ended");
System.out.println("-----------------");
}
}
In above program there are 5 instances of Test1 (extends Thread) class. All 5 threads are accessing Static method name display.
Now my question is that �do all threads (t1, t2, t3, t4, t5) in above program shares single copy of
static display method�.
My another question is that �if I replace code shown below with code in main in above program The result will be still same�.
Test1 t1=new Test1();
Thread d1=new Thread(t1);
Thread d2=new Thread(t1);
Thread d3=new Thread(t1);
Thread d4=new Thread(t1);
d1.start();
d2.start();
d3.start();
d4.start();
Thanks