Untitled
class Table1{ static synchronized void printTable(int n){ for(int i=0;i<=5;i++){ System.out.println(n*i); try{ Thread.sleep(1000); } catch(InterruptedException e){ System.out.println("Inturrept occur"); } } } } class Mythread3 extends Thread{ Table1 t; Mythread3(Table1 t){ this.t=t; } public void run(){ t.printTable(5); } } class Mythread4 extends Thread{ Table1 t; Mythread4(Table1 t){ this.t=t; } public void run(){ t.printTable(100); } } class ResultClass{ public static void main(String args[]){ Table1 obj1 = new Table1(); Table1 obj2 = new Table1(); Mythread3 t1= new Mythread3(obj1); Mythread3 t2= new Mythread3(obj2); Mythread4 t3= new Mythread4(obj1); Mythread4 t4= new Mythread4(obj2); t1.start(); t2.start(); t3.start(); t4.start(); } }
Leave a Comment