Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 553
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Java Wait/Notify

If 2 different threads issues a notify "simultaneus" will the wait always be capable to "fetch" both notifies?

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Java Wait/Notify

[ Edited ]

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.

Developer
Posts: 553
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Java Wait/Notify

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);  
    }

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-