aspose file tools*
The moose likes Threads and Synchronization and the fly likes problem with awakening after nofifyall is called GUI Swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "problem with awakening after nofifyall is called GUI Swing" Watch "problem with awakening after nofifyall is called GUI Swing" New topic
Author

problem with awakening after nofifyall is called GUI Swing

jeffrey odametey
Greenhorn

Joined: Mar 25, 2012
Posts: 5
this part is in another class and holds the thread/program untill the notifyall is called



once the button is pressed notifyall is called and the tester variable is changed to true but the system does not recognise this or the notify is not holding lock on this object and the previous thread does not awaken or continue



this is a small part of the program as in whole the whole program is 1000+ lines of code i have attached the files if you want to inspect the whole program

if you have the files type in this exactly:
MOVLW D'10'
MOVWF A
MOVLD D'20'
MOVWF A

please type in the textarea exactly as you see it with newline and all as it will generate errors if not done properly

press the parse button once the text is entered as you see it

the step button is supposed to allow the user to go through code step by step

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Wait an notify/notifyAll and the synchronization scheme in Java are all Object-specific. When you do wait() then it is like calling this.wait() and you will only way to notify the waiter is to call the notify() method on the same Object. You are wait()ing on one Object, notifyAll()ing on a different Object, and not synchronizing on a common Object either.


Steve
jeffrey odametey
Greenhorn

Joined: Mar 25, 2012
Posts: 5
thanks steve for your reply i figuired i was making a mistake along those lines but could you be more specific as pertaining to the code thnks
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

The first thing you should do is read a book or tutorial (or both) on threading in Java. Someplace to start is the Java Tutorial: http://docs.oracle.com/javase/tutorial/essential/concurrency/

Pertaining directly to your code: You need to provide some Object which is shared between both the Object which contains the first bit of code, and the Object which contains the notify() call. You then use that Object to synchronize on, and you also call wait() and notify() on that Object. As a quick guess - you have an Object - f1 - which holds your boo variable which you use in the while loop to make sure the wait() is not interrupted spuriously. You could probably synchronize on f1, then call f1.wait() and f1.notify() as appropriate.

I don't have your code (nor do I want to sift through 1000+ lines of code. But here is a rough sample:
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1089
    
  10

You can also think of using the Lock and Condition classes from the concurrency API - this makes it slightly easier for us to understand the program - simply because, we have to use the specific objects to invoke the methods...


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Alexei Kaigorodov
Greenhorn

Joined: Feb 24, 2008
Posts: 17
In most of the cases, there is no need to program low-level synchronization to support thread interaction - there are complete solutions.
First of all, one can use different kinds of Queues from java.util and java.util.concurrent.
For launching background thread from Swing, class javax.swing.SwingWorker can be used.
jeffrey odametey
Greenhorn

Joined: Mar 25, 2012
Posts: 5
thanks for the replies i will get back to you guys with my solution soon after applying your suggestions !
jeffrey odametey
Greenhorn

Joined: Mar 25, 2012
Posts: 5
Thanks for the replies guys
i solved it using the object lock and sync blocks

in one class it lets the program halt/wait



in button to wake the other class


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with awakening after nofifyall is called GUI Swing