• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with awakening after nofifyall is called GUI Swing

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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



 
reply
    Bookmark Topic Watch Topic
  • New Topic