File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with awakening after nofifyall is called GUI Swing

 
jeffrey odametey
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jeffrey odametey
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Alexei Kaigorodov
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the replies i will get back to you guys with my solution soon after applying your suggestions !
 
jeffrey odametey
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic