Skip to content

wait() and notify() method , always IllegalMonitorStateException is happen and tell me current Thread is not Owner Why?

package pkg_1;

public class ExpOnWaitMethod extends Thread {

    static Double x = new Double(20);

    public static void main(String[] args) {

        ExpOnWaitMethod T1 = new ExpOnWaitMethod();
        ExpOnWaitMethod T2 = new ExpOnWaitMethod();




    public void run() {

        Mag mag = new Mag();

        synchronized (x) {

            try {
                for (int i = 1; i < 10; i++) {
                    x = i * 2.0;


            } catch (InterruptedException e) {




class Mag {
    char ccc = 'A';

    public void nop(Thread thr) throws InterruptedException {

        System.out.print(ccc + " ");

        if (thr.getState().toString().equalsIgnoreCase("runnable"))


You need to hold the lock on the object you want to wait on (you can only call it within a synchronized block).

Also, calling wait on a Thread is very unusual and probably not what you want.

I am not sure what you are trying to do, but could you be confusing wait with sleep?

If you want to wait for another thread to finish, that would be anotherThread.join().