05-05-2012 04:31 PM
If 2 different threads issues a notify "simultaneus" will the wait always be capable to "fetch" both notifies?
05-05-2012 06:07 PM - edited 05-05-2012 06:07 PM
On the same object? I think you have to use a sync block around calls to wait and notify, so one would be called before the other, and if there are no other threads waiting on that object, the second notify should get ignored.
05-06-2012 03:23 AM
Hi, thanks.
3 parts involved The main task and several different threads. In theory the threads cannot execute the notify at the "same" time since there is sync block around the notify code. In practice the notyfies could be coming very close in time. I would assume, but do not know that the waiting task has priority or will react instantly to the first notify and that will cause the second notify to wait fon the synch.
The first notify is in the synch block, the second notify is hanging and waiting on the sync and the wait code is hanging and waiting on the wait statement . When the first notify releases the sync is the wait code the first to get control? I really hope so.
new Thread()
{
public void run()
{
try
{
synchronized(V_TestVector) //Own
{
V_TestVector.wait(CMDwaitms); //Ownership released
synchronized(V_TestVector) //Regain ownership Might not be needed here. Not sure
{
NotifyStringV = (String[]) V_TestVector.elementAt(0); //Get return values
} //end synchronized
} //end synchronization
}catch(Exception e33)
{
HandleAlert(_Setup.Error,"ReplytoCmndsWait error: "+ e33,0);
return;
}
And the notify code has it like this
try
{
synchronized(CallVector)
{
NotifyStringV[_Setup.WNStrMessage]= RetMsg;
CallVector.notify();
}
}catch (Exception E1)
{
HandleAlert(_Setup.Error,"Exception: "+E1,0);
}