android - java.lang.IllegalMonitorStateException: object not locked by thread before wait()? -


I'm progressing when user progressdialog off .unfortunately please give this exception to help me stop dialog.i thread Need for .

In the middle class

  class UpdateThread thread {Public runs zero} {while (true) {count = adapter.getCount (); Try {mHandler.post (New Runnable) {Public Zero Run} (Log.i (TAge, Count + "Count"); progressDialog.setMessage (Count + "Found Device")}}); Thread.Sleep (300); } Grip (Interrupted e) e.printStackTrace (); }}}  

turn on

  updateThread = new updateTread (); ProgressDialog = New Progress DiLoog (Group List of ActiveActivities); Synchronize (this) {updateThread.start (); } {Try {synchronize (it)) onDismissal  
  progressDialog.setOnDismissListener (New DialogInterface.OnDismissListener () {@Override Public Zero onDismiss (DialogInterface dialog) {UpdateThread.wait (300);}} Hold (InterruptedException E) {e.printStackTrace ();} Log.i (TAG, "Thread is Closed");}});  itemprop = "text"> 

This is incorrect:

  synchronize (foo    

} {Foo.wait (); }

The problem is, what is happening to wake up this thread? To say this, how do you guarantee do that other thread foo.notify () before will not call the first thread call> foo .wait () ? This is important because the Fu object will not remember that the notice call was informed before it was first. If there is only one (), and if wait () happens before, then waiting () will never return.

Here's how to wait and inform that it was to be used:

  Private queue  

The most important thing to note in this example is that there is a clear test for this condition (i.e., q.peek ()! = Null), and that anyone Does not change without lock lock.

If the user is called first, then the queue will be empty, and it will wait. Any moment, when the manufacturer can slip into, add a product to the queue, and then lock the lock until the consumer is ready to receive that information.

On the other hand, if the manufacturer is called first, then the consumer is guaranteed not to wait for the wait.

The loop in the consumer is important for two reasons: One is that, if more than one customer is a thread, then it is possible that a consumer will get a notification, but then another consumer queue Stealing the product from stealing the product. In that case, the fist is waiting for the next product to be the only proper thing for the consumer. The second reason is that the loop is important that Javadoc says the object. Wight () is allowed to go back, even when the item has not been informed. This is called "fake wake up", and the correct way to handle it is to go back and wait again.

Also keep in mind: lock is private and queue private . It guarantees that no other compilation unit is interfering in synchronization in this compilation unit.

And note: There is a separate object from the lock queue, it guarantees that synchronization in this compilation unit will not interfere with any synchronization that implements the queue (if any).


Note: To illustrate a point to a point, in the actual code again, you will use the (and) the method of Array BlinkQueu, which will wait for you Keeping all the notifications going will take care of


Comments