X Tutup
class Table{ public void printTable(int n){ synchronized(this){ for(int i=1;i<11;i++){ System.out.println(n*i); try{Thread.sleep(200);}catch(Exception e){} } } } } class MyThread extends Thread{ Table t; int n; MyThread(Table t,int n){ this.t = t; this.n = n; } public void run(){ t.printTable(n); } } class SynchronizationDemo3{ public static void main(String[] args){ Table tb = new Table(); MyThread t = new MyThread(tb,5); t.start(); MyThread t2 = new MyThread(tb,50); t2.start(); } }
X Tutup