Linked Questions
16 questions linked to/from java.lang.IllegalMonitorStateException: object not locked by thread before wait()?
2 votes
1 answer
4k views
Object not locked by thread before wait in Android app on Non Activity [duplicate]
I am calling a method CreateOne from Non-Activity class and CreateOne method needs to return an Object after Task execution. So I have addded the below line after calling the Task. task.wait(); But ...
0 votes
1 answer
2k views
How to properly use wait() and notify() in Java? (HiveMQ Client) [duplicate]
I've writing a program using HiveMQ Client (an MQTT Open source implementation in Java) that involves using two multithreaded clients. One client is designated as the publisher and the other as the ...
59 votes
2 answers
120k views
Java Wait and Notify: IllegalMonitorStateException
I don't completely understand how wait and notify (of Object) work, and as a result I'm forced to slim down my attempts into the following section of code. Main.java: import java.util.ArrayList; ...
3 votes
3 answers
2k views
How to understand if wait() returned from timeout or from a notify()?
I have a waiting thread: synchronized(sharedCounter) { while(sharedCounter > 0) { sharedCounter.wait(60000); //wait at most 1 minute /*if it wakens from the end of the timeout, it should ...
4 votes
1 answer
9k views
Object not locked by thread before wait in Android app
In my Android app I am trying to execute a task every 5 seconds. I tried doing something like this: @Override public void onCreate() { //standard initialization code letsChange(); ...
4 votes
4 answers
1k views
Leaked windows error with progress dialog android
I have a problem showing a progress dialog with an AsyncTask: Activity has leaked window com.android.internal.policy.PhoneWindow$DecorView{8cee959 V.E...... R......D 0,0-1026,252} that was ...
3 votes
1 answer
1k views
Deadlock caused by blocking methods
Say we create a thread which runs a synchronized method. This method tries to take() from an empty blocking queue. Now let a separate thread then try to put() and element onto the blocking queue while ...
0 votes
1 answer
2k views
Object not locked by thread before wait()?
I am trying below code to reboot my mobile bt_viewpakageroot.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { ...
0 votes
1 answer
1k views
How to pause and resume a Thread?
I have a thread: class SomeRunnable implements Runnable { @Override public void run() { while (true) { //some code... try { Thread.sleep(33); ...
3 votes
1 answer
704 views
Why does calling Thread.sleep in doInBackground() crash the application?
I'm using AsyncTask to pull data from my firebase and it works, however I'm using an empty while loop to ensure my database finishes it's operation before the Task moves on to the next step. I know in ...
0 votes
1 answer
729 views
how to update views with two concurrent threads Android
I have Character and a Monster, and want to simule a battle. To do so, I created two threads, one with the character's attack, and another with the monster's attack. Character and monster has ...
1 vote
1 answer
353 views
How can I let a thread wait successfully in Android?
I start 2 threads to receive messages in different pages (A and B) but cannot let one wait successfully. Here is the code of the receiveMsg thread. //BufferedReader brClient = new BufferedReader(new ...
0 votes
0 answers
239 views
Inter- thread communication
I have two threads running t1 and t2. When t2 notifies t1, immediately t2 should go to wait state. However, this is not possible as once it notifies t1, it should finish its current process and only ...
0 votes
2 answers
124 views
Java wait() notify()
I have the following code: public class ThreadA { public static void main(String[] args){ ThreadB b = new ThreadB(); b.start(); synchronized(b){ try{ b.wait(); ...
0 votes
1 answer
88 views
Can't understand this multi-threading exception behavior
According to the documentation for ReentrantLock.newCondition(), the calling thread needs to own a lock before calling a signaling method: If this lock is not held when any of the Condition waiting ...