class PrintNumber Wait Notify
class PrintNumber Wait Notify
{
synchronized void print(int n)
{
Thread t = Thread.currentThread();
String name = t.getName();
System.out.println(name);
for(int i = 1; i<=3 ; i++)
{
System.out.println(n*i);
try{Thread.sleep(400);} catch(Exception E){}
}
}
}
class Test
{
public static void main(String args[])
{
PrintNumber p = new PrintNumber();
MyThread t1 = new MyThread(p,2);
MyThread t2 = new MyThread(p,3);
t1.start();
t2.start();
}
}
class PrintNumber
{
void print(int n)
{
Thread t = Thread.currentThread();
String name = t.getName();
System.out.println(name);
synchronized(this){
if(n==2)
try{wait();} catch(Exception E){};
class TestWait
{
public static void main(String args[])
{
PrintNumber p = new PrintNumber();
MyThread t1 = new MyThread(p,2);
MyThread t2 = new MyThread(p,3);
t1.start();
t2.start();
}
}