有关同步的理解
关键字:synchronized(对象名) {}
用这个关键字来锁定某个线程A
非OOP的编程思想,可以写为如下的代码:
----------------------线程A---------------------------------------------------------
if(条件1)
{
try
{
synchronized(this)
{
wait(); //线程A等待
}
}catch(InterruptedException e) {}
}
//非条件1下
synchronized(线程B)
{
线程B. notify();
}
-------------------------线程B-----------------------------------------------------------
if(非条件1)
{
try
{
synchroized(this)
{
wait();
}
}catch(InterruptedException e) {}
}
//条件1下
synchronized(线程A)
{
线程A. notify();
}