below is a simplified version of the wait-notify scenario I'm trying to implement and I'm really struggling to make it work. I'm completely missing how to invoke notify() on object instance of Class A, and am not sure what to put in the synchronized() parenthesis, and why.
Appreciate any help. Thanks
public class A implements Runnable{
private B b;
@Override
public void run()
{
b = new B()
Thread bThread = new Thread(b);
bThread.start()
synchronized(this)
{
while(something)
{
try
{
wait();
}
catch (Exception e){}
}
}
}
}
public class B implements Runnable{
@Override
public void run()
{
doSomething();
synchronized(this)
{
try
{
notify();
}
catch (Exception e){}
}
}
}