• 0

[Java] .wait() and .notify()


Question

I having some trouble with the IllegalMonitorStateException being thrown because I'm not calling notify from the correct place that is the monitor of the object I'm suspending. Unfortunatly I can't work out there the correct place is.

My setup is as follows:

main - creates a new object X
     Action Event Thread - X uses a listener on an event which executes in Action Event Thread
          Swing worker Thread - the action event thread creates a worker thread which runs a syncronised method in X

The method in X launches a dialog box then uses Thread.currentThread().wait(); to hold the worker thread.

Once the dialog box recieves another user action I want to resume the worker thread but can't seem to find the right place to do so sucessfully.

Do I need to notify the suspended thread from the thread that started the swing worker and if so, in this case, which thread is that? main, the action despatch thread or something else?

I have tried simply passing on the paused thread as a variable before hand so I can call thread.notify() from another synchronised method in X, but to no avail.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Ahh, I have worked around the problem, if your in this situation then there is no need to suspend the thread as my second action was also based off a user generated action, so I could split the methods and simply call the second method from the second user action.

I'm still interested to find out what thread actually owns the monitor for the worker thread generated in the action despatch thread for the future though.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.